@financial-times/dotcom-build-base 7.3.1 → 7.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -2
  2. package/src/index.ts +54 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/dotcom-build-base",
3
- "version": "7.3.1",
3
+ "version": "7.3.2",
4
4
  "description": "The Page Kit CLI",
5
5
  "main": "dist/node/index.js",
6
6
  "types": "src/index.ts",
@@ -34,7 +34,8 @@
34
34
  "npm": "7.x || 8.x"
35
35
  },
36
36
  "files": [
37
- "dist/"
37
+ "dist/",
38
+ "src/"
38
39
  ],
39
40
  "repository": {
40
41
  "type": "git",
package/src/index.ts ADDED
@@ -0,0 +1,54 @@
1
+ import type webpack from 'webpack'
2
+ import path from 'path'
3
+ import { CleanWebpackPlugin } from 'clean-webpack-plugin'
4
+ import CompressionPlugin from 'compression-webpack-plugin'
5
+ import ManifestPlugin from 'webpack-assets-manifest'
6
+
7
+ export class PageKitBasePlugin {
8
+ apply(compiler: webpack.Compiler) {
9
+ const isDevMode = compiler.options.mode === 'development'
10
+
11
+ const outputFileName = isDevMode ? '[name].bundle.js' : '[name].[contenthash:12].bundle.js'
12
+
13
+ const cleanWebpackPluginOptions = { verbose: false }
14
+
15
+ const gzipCompressionPluginOptions = {
16
+ test: /\.(js|css)$/,
17
+ filename: '[path].gz',
18
+ algorithm: 'gzip',
19
+ compressionOptions: { level: 9 },
20
+ minRatio: 1
21
+ }
22
+
23
+ const brotliCompressionPluginOptions = {
24
+ test: /\.(js|css)$/,
25
+ filename: '[path].br',
26
+ algorithm: 'brotliCompress',
27
+ compressionOptions: { level: 11 },
28
+ minRatio: 1
29
+ }
30
+
31
+ const manifestPluginOptions = {
32
+ entrypoints: true
33
+ }
34
+
35
+ compiler.options.output = {
36
+ ...compiler.options.output,
37
+ filename: outputFileName,
38
+ chunkFilename: outputFileName,
39
+ path: path.resolve('public')
40
+ }
41
+
42
+ compiler.options.devtool = isDevMode ? 'cheap-module-eval-source-map' : 'source-map'
43
+
44
+ compiler.options.bail = !isDevMode
45
+
46
+ new CleanWebpackPlugin(cleanWebpackPluginOptions).apply(compiler)
47
+ new ManifestPlugin(manifestPluginOptions).apply(compiler)
48
+
49
+ if (!isDevMode) {
50
+ new CompressionPlugin(gzipCompressionPluginOptions).apply(compiler)
51
+ new CompressionPlugin(brotliCompressionPluginOptions).apply(compiler)
52
+ }
53
+ }
54
+ }