Skip to content

Commit

Permalink
add mini css extract
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew44-mappable committed Oct 14, 2024
1 parent 908a50a commit ca8fc96
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 11 deletions.
86 changes: 86 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"jest": "29.6.1",
"jsdom": "22.1.0",
"lodash": "^4.17.21",
"mini-css-extract-plugin": "^2.9.1",
"nanospinner": "^1.1.0",
"postcss": "^8.4.39",
"postcss-loader": "^8.1.1",
Expand Down
31 changes: 20 additions & 11 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');

const ESM_BUILD = process.env.ESM_BUILD === 'true';

const replaceStyleLoaderToCssExtract = (moduleRules) => {
moduleRules.forEach((loaderRule) => {
if (!loaderRule.use) {
return;
}
loaderRule.use.forEach((loader, index) => {
if (loader === 'style-loader') {
loaderRule.use[index] = MiniCssExtractPlugin.loader;
}
});
});
};

module.exports = (args, env, dir = process.cwd()) => {
const coreWebpackModule = require('@mappable-world/mappable-cli/webpack.config')(args, env, dir);

if (ESM_BUILD) {
coreWebpackModule.experiments = {
outputModule: true
};
coreWebpackModule.entry = {
index: {
import: './src/index.ts',
library: {
type: 'module'
}
}
};
coreWebpackModule.experiments = {outputModule: true};
coreWebpackModule.entry = {index: {import: './src/index.ts', library: {type: 'module'}}};
coreWebpackModule.output.path = path.resolve(dir, 'dist/esm');
coreWebpackModule.plugins = [new MiniCssExtractPlugin()];
replaceStyleLoaderToCssExtract(coreWebpackModule.module.rules);
}

return coreWebpackModule;
};

0 comments on commit ca8fc96

Please sign in to comment.