Skip to content

Commit 0c0a1ed

Browse files
committed
Build improvements
- Upgrade to [email protected] - Add runtime chunk, disable default chunk, and force modules into main chunk - Fix linting issue in the test config - Fix the generated css file name - Filter css order warnings - Move optimize-css-assets-webpack-plugin to dist config
1 parent efac215 commit 0c0a1ed

File tree

8 files changed

+61
-45
lines changed

8 files changed

+61
-45
lines changed

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"webpack-dev-middleware": "3.4.0",
147147
"webpack-hot-middleware": "2.24.3",
148148
"webpack-manifest-plugin": "2.0.4",
149-
"webpack-mild-compile": "2.0.0",
149+
"webpack-mild-compile": "3.3.1",
150150
"webpack-pwa-manifest": "3.7.1",
151151
"wrapper-webpack-plugin": "2.0.0"
152152
}

src/base.config.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const postcssImport = require('postcss-import');
1616
const IgnorePlugin = require('webpack/lib/IgnorePlugin');
1717
const slash = require('slash');
1818
const WrapperPlugin = require('wrapper-webpack-plugin');
19-
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
2019

2120
const basePath = process.cwd();
2221
const srcPath = path.join(basePath, 'src');
@@ -306,6 +305,19 @@ export default function webpackConfigFactory(args: any): webpack.Configuration {
306305
modules: [basePath, path.join(basePath, 'node_modules')],
307306
extensions
308307
},
308+
optimization: {
309+
splitChunks: {
310+
cacheGroups: {
311+
default: false,
312+
main: {
313+
chunks: 'initial',
314+
minChunks: 1,
315+
name: 'main',
316+
reuseExistingChunk: true
317+
}
318+
}
319+
}
320+
},
309321
devtool: 'source-map',
310322
watchOptions: { ignored: /node_modules/ },
311323
plugins: removeEmpty([
@@ -316,13 +328,7 @@ export default function webpackConfigFactory(args: any): webpack.Configuration {
316328
new CssModulePlugin(basePath),
317329
new IgnorePlugin(/request\/providers\/node/),
318330
new MiniCssExtractPlugin({
319-
filename: 'main.css'
320-
}),
321-
new OptimizeCssAssetsPlugin({
322-
cssProcessor: require('cssnano'),
323-
cssProcessorPluginOptions: {
324-
preset: ['default', { calc: false }]
325-
}
331+
filename: '[name].css'
326332
}),
327333
(args.externals || isTest) &&
328334
new WrapperPlugin({

src/base.test.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function webpackConfig(args: any): webpack.Configuration {
1111
const instrumenterOptions = args.legacy ? {} : { esModules: true };
1212

1313
config.plugins = [
14-
...plugins,
14+
...plugins!,
1515
new WrapperPlugin({
1616
test: /(all.*(\.js$))/,
1717
footer: `typeof define === 'function' && define.amd && define(['${libraryName}'], function() {});`

src/dev.config.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,7 @@ function webpackConfig(args: any): webpack.Configuration {
2626
if (!args.singleBundle) {
2727
config.optimization = {
2828
...config.optimization,
29-
splitChunks: {
30-
cacheGroups: {
31-
runtime: {
32-
name: 'runtime',
33-
chunks: 'initial'
34-
}
35-
}
36-
}
29+
runtimeChunk: { name: 'runtime' }
3730
};
3831
}
3932

src/dist.config.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { WebAppManifest } from './interfaces';
1717

1818
const BrotliPlugin = require('brotli-webpack-plugin');
1919
const CompressionPlugin = require('compression-webpack-plugin');
20+
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
2021
const TerserPlugin = require('terser-webpack-plugin');
2122
const WebpackPwaManifest = require('webpack-pwa-manifest');
2223

@@ -40,17 +41,20 @@ function webpackConfig(args: any): webpack.Configuration {
4041

4142
config.optimization = {
4243
...config.optimization,
43-
minimizer: [new TerserPlugin({ sourceMap: true, cache: true })]
44+
minimizer: [
45+
new TerserPlugin({ sourceMap: true, cache: true }),
46+
new OptimizeCssAssetsPlugin({
47+
cssProcessor: require('cssnano'),
48+
cssProcessorPluginOptions: {
49+
preset: ['default', { calc: false }]
50+
}
51+
})
52+
]
4453
};
4554

4655
if (!args.singleBundle) {
47-
config.optimization.splitChunks = {
48-
cacheGroups: {
49-
runtime: {
50-
name: 'runtime',
51-
chunks: 'initial'
52-
}
53-
}
56+
config.optimization.runtimeChunk = {
57+
name: 'runtime'
5458
};
5559
}
5660

src/main.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function build(config: webpack.Configuration, args: any) {
5555
}
5656
if (stats) {
5757
const runningMessage = args.serve ? `Listening on port ${args.port}...` : '';
58-
const hasErrors = logger(stats.toJson(), config, runningMessage);
58+
const hasErrors = logger(stats.toJson({ warningsFilter }), config, runningMessage);
5959
if (hasErrors) {
6060
reject({});
6161
return;
@@ -97,7 +97,7 @@ function fileWatch(config: webpack.Configuration, args: any): Promise<void> {
9797
}
9898
if (stats) {
9999
const runningMessage = args.serve ? `Listening on port ${args.port}` : 'watching...';
100-
logger(stats.toJson(), config, runningMessage);
100+
logger(stats.toJson({ warningsFilter }), config, runningMessage);
101101
}
102102
resolve();
103103
});
@@ -119,7 +119,7 @@ function memoryWatch(config: webpack.Configuration, args: any, app: express.Appl
119119
const compiler = createWatchCompiler(config);
120120

121121
compiler.hooks.done.tap('@dojo/cli-build-app', (stats) => {
122-
logger(stats.toJson(), config, `Listening on port ${args.port}...`);
122+
logger(stats.toJson({ warningsFilter }), config, `Listening on port ${args.port}...`);
123123
});
124124

125125
app.use(
@@ -238,6 +238,10 @@ function serve(config: webpack.Configuration, args: any): Promise<void> {
238238
});
239239
}
240240

241+
function warningsFilter(warning: string) {
242+
return warning.includes('[mini-css-extract-plugin]\nConflicting order between');
243+
}
244+
241245
const command: Command = {
242246
group: 'build',
243247
name: 'app',

tests/unit/main.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ describe('command', () => {
3939
exitStub = stub(process, 'exit');
4040
isError = false;
4141
stats = {
42-
toJson() {
43-
return 'stats';
44-
}
42+
toJson: stub().returns('stats')
4543
};
4644
mockModule = new MockModule('../../src/main', require);
4745
mockModule.dependencies([
@@ -172,6 +170,17 @@ describe('command', () => {
172170
});
173171
});
174172

173+
it('filters CSS module order warnings from the logger', () => {
174+
const main = mockModule.getModuleUnderTest().default;
175+
return main.run(getMockConfiguration(), { mode: 'unit' }).then(() => {
176+
const [{ warningsFilter }] = stats.toJson.firstCall.args;
177+
assert.isTrue(warningsFilter('[mini-css-extract-plugin]\nConflicting order between'));
178+
assert.isFalse(warningsFilter('[mini-css-extract-plugin]'));
179+
assert.isFalse(warningsFilter(''));
180+
assert.isFalse(warningsFilter('some other warning'));
181+
});
182+
});
183+
175184
it('mixes in features from command line', () => {
176185
const main = mockModule.getModuleUnderTest().default;
177186
return main

0 commit comments

Comments
 (0)