Skip to content

Commit

Permalink
Merge pull request #30 from Videodock/optimize
Browse files Browse the repository at this point in the history
Optimize
  • Loading branch information
ChristiaanScheermeijer authored Jun 7, 2021
2 parents 60a350a + 7dbebf2 commit 0e4ef25
Show file tree
Hide file tree
Showing 4 changed files with 502 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
5 changes: 5 additions & 0 deletions scripts/webpack/css-modules-fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function cssModulesFix(source) {
return source.replace(/_(\w+)_[\w\d]{5}_\d+/g, function(fullMatch, originalSelector) {
return originalSelector;
});
};
57 changes: 30 additions & 27 deletions snowpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,36 @@ 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')));
const cssModulesRule = config.module.rules.find((rule) =>
rule && rule.use && rule.use.find((use) => use && use.loader && use.loader.includes('css-loader') && use.options && use.options.modules));

if (cssModulesRule) {
cssModulesRule.use.unshift({
loader: require.resolve('./scripts/webpack/css-modules-fix.js'),
});
}

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'
]);
}

return true;
});
}

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

0 comments on commit 0e4ef25

Please sign in to comment.