packages/cli: extract css in bundle prod builds

This commit is contained in:
Patrik Oldsberg
2020-05-16 23:45:53 +02:00
parent d911db4105
commit d1939be664
3 changed files with 46 additions and 1 deletions
+2
View File
@@ -54,6 +54,7 @@
"jest": "^25.1.0",
"jest-css-modules": "^2.1.0",
"jest-esm-transformer": "^1.0.0",
"mini-css-extract-plugin": "^0.9.0",
"ora": "^4.0.3",
"raw-loader": "^4.0.1",
"react": "^16.0.0",
@@ -81,6 +82,7 @@
"@types/fs-extra": "^8.1.0",
"@types/html-webpack-plugin": "^3.2.2",
"@types/inquirer": "^6.5.0",
"@types/mini-css-extract-plugin": "^0.9.1",
"@types/node": "^13.7.2",
"@types/ora": "^3.2.0",
"@types/react-dev-utils": "^9.0.4",
+27 -1
View File
@@ -16,6 +16,7 @@
import webpack, { Module, Plugin } from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import { BundlingOptions } from './types';
import { BundlingPaths } from './paths';
@@ -65,7 +66,25 @@ export const transforms = (
},
{
test: /\.css$/i,
use: [require.resolve('style-loader'), require.resolve('css-loader')],
use: [
isDev
? {
loader: require.resolve('style-loader'),
options: {
attrs: { origin: 'main' },
},
}
: {
loader: MiniCssExtractPlugin.loader,
},
{
loader: require.resolve('css-loader'),
options: {
sourceMap: true,
},
},
],
},
];
@@ -79,6 +98,13 @@ export const transforms = (
if (isDev) {
plugins.push(new webpack.HotModuleReplacementPlugin());
} else {
plugins.push(
new MiniCssExtractPlugin({
filename: '[name].[contenthash:8].css',
chunkFilename: '[name].[id].[contenthash:8].css',
}),
);
}
return { loaders, plugins };