Skip to content

Commit cf34663

Browse files
committed
Update plugin order
1 parent fc900ee commit cf34663

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

packages/dotcom-page-kit-cli/README.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ page-kit --help
3737

3838
This action can be used to assemble the static assets for your application using Webpack. By default this action includes only a barebones Webpack configuration to bundle JavaScript source code but this can be extended via plugins to add additional functionality.
3939

40+
The action also creates a `manifest.json` (the file name is default but can be [configured](#Manifest-file-name)). It includes the hashed output names for the generated `.js` and `.css` chunks
41+
4042
#### Options
4143

4244
##### Entry points
@@ -93,7 +95,7 @@ Files will be created using the pattern `[name].js` in development mode and `[na
9395

9496
##### Manifest file name
9597

96-
The name of the generated manifest file can be changed via the configuration file. The default file name is `"manifest.json"`.
98+
The generated manifest file details the hashed output names for the emitted `.js` and `.css` chunks. The file name can be changed via the configuration file. The default file name is `"manifest.json"`.
9799

98100
Usage via configuration file:
99101

@@ -161,14 +163,22 @@ import { hooks } from '@financial-times/dotcom-page-kit-cli'
161163

162164
_Please note: The hooks below are listed in the order they will be executed._
163165

164-
##### `WEBPACK_MANIFEST_PLUGIN_OPTIONS`
165-
166-
Configuration options for the [assets manifest plugin](https://github.com/webdeveric/webpack-assets-manifest).
167-
168166
##### `WEBPACK_CLEAN_PLUGIN_OPTIONS`
169167

170168
Configuration options for the [clean plugin](https://github.com/johnagan/clean-webpack-plugin).
171169

170+
##### `WEBPACK_COMPRESSION_PLUGIN_OPTIONS`
171+
172+
Configuration options for the [compression plugin](https://github.com/webpack-contrib/compression-webpack-plugin)
173+
174+
##### `WEBPACK_BROTLI_PLUGIN_OPTIONS`
175+
176+
Configuration options for the [brotli compression plugin](https://github.com/mynameiswhm/brotli-webpack-plugin)
177+
178+
##### `WEBPACK_MANIFEST_PLUGIN_OPTIONS`
179+
180+
Configuration options for the [assets manifest plugin](https://github.com/webdeveric/webpack-assets-manifest) which provides the compilation entrypoints for each bundle by asset type e.g. `scripts` and `styles`.
181+
172182
##### `BABEL_CONFIG`
173183

174184
Configuration options for [Babel](https://babeljs.io/docs/en/options).
@@ -183,14 +193,6 @@ The Webpack [rule] for handling JavaScript files.
183193

184194
[rule]: https://webpack.js.org/configuration/module/#rule
185195

186-
##### `WEBPACK_COMPRESSION_PLUGIN_OPTIONS`
187-
188-
Configuration options for the [compression plugin](https://github.com/webpack-contrib/compression-webpack-plugin)
189-
190-
##### `WEBPACK_BROTLI_PLUGIN_OPTIONS`
191-
192-
Configuration options for the [brotli compression plugin](https://github.com/mynameiswhm/brotli-webpack-plugin)
193-
194196
##### `WEBPACK_CONFIG`
195197

196198
The complete Webpack configuration object.

packages/dotcom-page-kit-cli/src/operations/getWebpackConfig.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ import get from 'lodash.get'
22
import { hooks } from '../entities/hooks'
33
import { CliContext } from '../entities/CliContext'
44
import { getBabelConfig } from './getBabelConfig'
5-
import ManifestPlugin from 'webpack-assets-manifest'
65
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
76
import CompressionPlugin from 'compression-webpack-plugin'
87
import BrotliPlugin from 'brotli-webpack-plugin'
8+
import ManifestPlugin from 'webpack-assets-manifest'
99

1010
export function getWebpackConfig({ options, config, publish, cli }: CliContext) {
1111
const isDevMode = options.development
1212
const entryOptions = get(config, 'settings.build.entry') || options.entryFile
1313
const outputPath = get(config, 'settings.build.outputPath') || options.outputPath
1414
const outputFileName = isDevMode ? '[name].bundle.js' : '[name].[contenthash:12].bundle.js'
15-
const manifestFileName = get(config, 'settings.build.manifestFileName') || 'manifest.json'
16-
const manifestPluginOptions = { output: manifestFileName, entrypoints: true }
1715
const cleanWebpackPluginOptions = { verbose: false }
1816
const compressionPluginOptions = {
1917
test: /\.(js|css)$/,
@@ -22,11 +20,16 @@ export function getWebpackConfig({ options, config, publish, cli }: CliContext)
2220
minRatio: 1
2321
}
2422
const brotliPluginOptions = { test: /\.(js|css)$/, quality: 11, minRatio: 1 }
23+
const manifestFileName = get(config, 'settings.build.manifestFileName') || 'manifest.json'
24+
const manifestPluginOptions = {
25+
output: manifestFileName,
26+
entrypoints: true
27+
}
2528

26-
publish(hooks.WEBPACK_MANIFEST_PLUGIN_OPTIONS, manifestPluginOptions)
2729
publish(hooks.WEBPACK_CLEAN_PLUGIN_OPTIONS, cleanWebpackPluginOptions)
2830
publish(hooks.WEBPACK_COMPRESSION_PLUGIN_OPTIONS, compressionPluginOptions)
2931
publish(hooks.WEBPACK_BROTLI_PLUGIN_OPTIONS, brotliPluginOptions)
32+
publish(hooks.WEBPACK_MANIFEST_PLUGIN_OPTIONS, manifestPluginOptions)
3033

3134
return publish(hooks.WEBPACK_CONFIG, {
3235
mode: isDevMode ? 'development' : 'production',
@@ -57,11 +60,11 @@ export function getWebpackConfig({ options, config, publish, cli }: CliContext)
5760
? [new CleanWebpackPlugin(cleanWebpackPluginOptions), new ManifestPlugin(manifestPluginOptions)]
5861
: [
5962
new CleanWebpackPlugin(cleanWebpackPluginOptions),
60-
new ManifestPlugin(manifestPluginOptions),
6163
new CompressionPlugin(compressionPluginOptions),
6264
// TODO: Swap BrotliPlugin for another instance of CompressionPlugin when on node >=11.7.0
6365
// https://www.npmjs.com/package/compression-webpack-plugin#using-brotli
64-
new BrotliPlugin(brotliPluginOptions)
66+
new BrotliPlugin(brotliPluginOptions),
67+
new ManifestPlugin(manifestPluginOptions)
6568
],
6669
devtool: isDevMode ? 'cheap-module-eval-source-map' : 'source-map',
6770
bail: isDevMode ? false : true

0 commit comments

Comments
 (0)