Skip to content

Commit

Permalink
Build improvements
Browse files Browse the repository at this point in the history
- Upgrade to webpack-mild-compile@3.3.1
- 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
  • Loading branch information
mwistrand committed Nov 22, 2018
1 parent efac215 commit 0c0a1ed
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 45 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"webpack-dev-middleware": "3.4.0",
"webpack-hot-middleware": "2.24.3",
"webpack-manifest-plugin": "2.0.4",
"webpack-mild-compile": "2.0.0",
"webpack-mild-compile": "3.3.1",
"webpack-pwa-manifest": "3.7.1",
"wrapper-webpack-plugin": "2.0.0"
}
Expand Down
22 changes: 14 additions & 8 deletions src/base.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const postcssImport = require('postcss-import');
const IgnorePlugin = require('webpack/lib/IgnorePlugin');
const slash = require('slash');
const WrapperPlugin = require('wrapper-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');

const basePath = process.cwd();
const srcPath = path.join(basePath, 'src');
Expand Down Expand Up @@ -306,6 +305,19 @@ export default function webpackConfigFactory(args: any): webpack.Configuration {
modules: [basePath, path.join(basePath, 'node_modules')],
extensions
},
optimization: {
splitChunks: {
cacheGroups: {
default: false,
main: {
chunks: 'initial',
minChunks: 1,
name: 'main',
reuseExistingChunk: true
}
}
}
},
devtool: 'source-map',
watchOptions: { ignored: /node_modules/ },
plugins: removeEmpty([
Expand All @@ -316,13 +328,7 @@ export default function webpackConfigFactory(args: any): webpack.Configuration {
new CssModulePlugin(basePath),
new IgnorePlugin(/request\/providers\/node/),
new MiniCssExtractPlugin({
filename: 'main.css'
}),
new OptimizeCssAssetsPlugin({
cssProcessor: require('cssnano'),
cssProcessorPluginOptions: {
preset: ['default', { calc: false }]
}
filename: '[name].css'
}),
(args.externals || isTest) &&
new WrapperPlugin({
Expand Down
2 changes: 1 addition & 1 deletion src/base.test.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function webpackConfig(args: any): webpack.Configuration {
const instrumenterOptions = args.legacy ? {} : { esModules: true };

config.plugins = [
...plugins,
...plugins!,
new WrapperPlugin({
test: /(all.*(\.js$))/,
footer: `typeof define === 'function' && define.amd && define(['${libraryName}'], function() {});`
Expand Down
9 changes: 1 addition & 8 deletions src/dev.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@ function webpackConfig(args: any): webpack.Configuration {
if (!args.singleBundle) {
config.optimization = {
...config.optimization,
splitChunks: {
cacheGroups: {
runtime: {
name: 'runtime',
chunks: 'initial'
}
}
}
runtimeChunk: { name: 'runtime' }
};
}

Expand Down
20 changes: 12 additions & 8 deletions src/dist.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { WebAppManifest } from './interfaces';

const BrotliPlugin = require('brotli-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const WebpackPwaManifest = require('webpack-pwa-manifest');

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

config.optimization = {
...config.optimization,
minimizer: [new TerserPlugin({ sourceMap: true, cache: true })]
minimizer: [
new TerserPlugin({ sourceMap: true, cache: true }),
new OptimizeCssAssetsPlugin({
cssProcessor: require('cssnano'),
cssProcessorPluginOptions: {
preset: ['default', { calc: false }]
}
})
]
};

if (!args.singleBundle) {
config.optimization.splitChunks = {
cacheGroups: {
runtime: {
name: 'runtime',
chunks: 'initial'
}
}
config.optimization.runtimeChunk = {
name: 'runtime'
};
}

Expand Down
10 changes: 7 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function build(config: webpack.Configuration, args: any) {
}
if (stats) {
const runningMessage = args.serve ? `Listening on port ${args.port}...` : '';
const hasErrors = logger(stats.toJson(), config, runningMessage);
const hasErrors = logger(stats.toJson({ warningsFilter }), config, runningMessage);
if (hasErrors) {
reject({});
return;
Expand Down Expand Up @@ -97,7 +97,7 @@ function fileWatch(config: webpack.Configuration, args: any): Promise<void> {
}
if (stats) {
const runningMessage = args.serve ? `Listening on port ${args.port}` : 'watching...';
logger(stats.toJson(), config, runningMessage);
logger(stats.toJson({ warningsFilter }), config, runningMessage);
}
resolve();
});
Expand All @@ -119,7 +119,7 @@ function memoryWatch(config: webpack.Configuration, args: any, app: express.Appl
const compiler = createWatchCompiler(config);

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

app.use(
Expand Down Expand Up @@ -238,6 +238,10 @@ function serve(config: webpack.Configuration, args: any): Promise<void> {
});
}

function warningsFilter(warning: string) {
return warning.includes('[mini-css-extract-plugin]\nConflicting order between');
}

const command: Command = {
group: 'build',
name: 'app',
Expand Down
15 changes: 12 additions & 3 deletions tests/unit/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ describe('command', () => {
exitStub = stub(process, 'exit');
isError = false;
stats = {
toJson() {
return 'stats';
}
toJson: stub().returns('stats')
};
mockModule = new MockModule('../../src/main', require);
mockModule.dependencies([
Expand Down Expand Up @@ -172,6 +170,17 @@ describe('command', () => {
});
});

it('filters CSS module order warnings from the logger', () => {
const main = mockModule.getModuleUnderTest().default;
return main.run(getMockConfiguration(), { mode: 'unit' }).then(() => {
const [{ warningsFilter }] = stats.toJson.firstCall.args;
assert.isTrue(warningsFilter('[mini-css-extract-plugin]\nConflicting order between'));
assert.isFalse(warningsFilter('[mini-css-extract-plugin]'));
assert.isFalse(warningsFilter(''));
assert.isFalse(warningsFilter('some other warning'));
});
});

it('mixes in features from command line', () => {
const main = mockModule.getModuleUnderTest().default;
return main
Expand Down

0 comments on commit 0c0a1ed

Please sign in to comment.