Skip to content

Commit

Permalink
fix(project): fix snowpack optimize using webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed Jun 3, 2021
1 parent 7c60d52 commit 4a2883f
Show file tree
Hide file tree
Showing 3 changed files with 494 additions and 87 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<body>
<div id="root"></div>
<noscript>You need to enable JavaScript to run this app.</noscript>
<script type="module" src="/dist/index.js"></script>
<script>
var urlSearchParams = new URLSearchParams(window.location.search);
var configId =
Expand All @@ -46,6 +45,7 @@
window.configLocation = './config.json';
}
</script>
<script type="module" src="/dist/index.js"></script>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
Expand Down
54 changes: 27 additions & 27 deletions snowpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ module.exports = {
'@snowpack/plugin-react-refresh',
'@snowpack/plugin-dotenv',
'@snowpack/plugin-sass',
// ['@snowpack/plugin-webpack', {
// extendConfig: (config) => {
// // FIXES https://github.com/snowpackjs/snowpack/discussions/2810
// config.module.rules.find(
// (rule) =>
// rule &&
// rule.use &&
// rule.use.find((use) => {
// if (
// !use ||
// !use.loader ||
// !use.loader.includes('babel-loader')
// ) {
// return null;
// }
//
// use.options.plugins = (use.options.plugins || []).concat([
// '@babel/plugin-proposal-optional-chaining',
// '@babel/plugin-proposal-nullish-coalescing-operator'
// ]);
//
// return use;
// }),
// );
// return config;
// },
// }],
['@snowpack/plugin-webpack', {
extendConfig: (config) => {
// FIXES https://github.com/snowpackjs/snowpack/discussions/2810
const babelRule = config.module.rules.find((rule) =>
rule && rule.use && rule.use.find((use) => use && use.loader && use.loader.includes('babel-loader')));

if (babelRule) {
babelRule.use = babelRule.use.filter(use => {
if (use.loader.includes('babel-loader')) {
use.options.plugins = (use.options.plugins || []).concat([
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator'
]);
}

// filter out proxy-import-resolve
if (use.loader.includes('proxy-import-resolve')) {
return false;
}

return true;
});
}

return config;
},
}],
[
'@snowpack/plugin-typescript',
{
Expand Down
Loading

0 comments on commit 4a2883f

Please sign in to comment.