@lipemat/js-boilerplate 9.1.0-beta.4 → 9.2.0-beta.1

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.
@@ -26,8 +26,8 @@ module.exports = {
26
26
  },
27
27
  headers: {
28
28
  'Access-Control-Allow-Origin': '*',
29
- 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
30
- 'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
29
+ 'Access-Control-Allow-Methods': '*',
30
+ 'Access-Control-Allow-Headers': '*',
31
31
  },
32
32
  host: '0.0.0.0', // Allow connections from any IP.
33
33
  hot: true,
@@ -3,10 +3,10 @@ const moduleHelpers = require( '../helpers/modules' );
3
3
  const webpack = require( 'webpack' );
4
4
  const path = require( 'path' );
5
5
  const fs = require( 'fs' );
6
+ const crypto = require( 'node:crypto' );
6
7
  const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
7
- const WebpackCleanupPlugin = require( '@lipemat/webpack-cleanup-plugin' );
8
+ const {CleanWebpackPlugin} = require( 'clean-webpack-plugin' );
8
9
  const WebpackAssetsManifest = require( 'webpack-assets-manifest' );
9
- const SriPlugin = require( 'webpack-subresource-integrity' );
10
10
  const config = require( '../helpers/package-config' );
11
11
 
12
12
  const postcssOptions = getConfig( 'postcss.config.js' );
@@ -79,13 +79,19 @@ module.exports = {
79
79
  filename: '[name].css',
80
80
  chunkFilename: '[name].[chunkhash].css',
81
81
  } ),
82
- new WebpackCleanupPlugin(),
83
- new SriPlugin( {
84
- hashFuncNames: [ 'sha256', 'sha384', 'sha512' ],
82
+ new CleanWebpackPlugin( {
83
+ // Remove all files except the `.running` file created by "Start".
84
+ cleanOnceBeforeBuildPatterns: [ '**/*', '!.running' ],
85
85
  } ),
86
86
  new WebpackAssetsManifest( {
87
87
  integrity: true,
88
88
  output: 'manifest.json',
89
+ //Add a `hash` so every item in the manifest for browser cache flushing.
90
+ transform( assets ) {
91
+ Object.keys( assets ).forEach( item => {
92
+ assets[ item ].hash = crypto.createHash( 'md5' ).update( assets[ item ].integrity ).digest( 'hex' );
93
+ } );
94
+ },
89
95
  } ),
90
96
  ],
91
97
  module: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lipemat/js-boilerplate",
3
- "version": "9.1.0-beta.4",
3
+ "version": "9.2.0-beta.1",
4
4
  "description": "Dependencies and scripts for a no config JavaScript app",
5
5
  "author": "Mat Lipe",
6
6
  "license": "MIT",
@@ -50,9 +50,10 @@
50
50
  "@wordpress/browserslist-config": "^4.1.0",
51
51
  "are-you-es5": "^2.1.1",
52
52
  "babel-jest": "^29.0.0",
53
- "babel-loader": "^8.2.2",
53
+ "babel-loader": "^9.1.2",
54
54
  "browserslist": "^4.17.0",
55
55
  "clean-css": "^5.3.0",
56
+ "clean-webpack-plugin": "^4.0.0",
56
57
  "core-js": "^3.8.3",
57
58
  "cross-spawn": "^6.0.5",
58
59
  "css-loader": "6.7.1",
@@ -81,8 +82,7 @@
81
82
  "webpack": "^5.72.1",
82
83
  "webpack-assets-manifest": "^5.0.6",
83
84
  "webpack-cli": "^4.9.1",
84
- "webpack-dev-server": "^4.7.2",
85
- "webpack-subresource-integrity": "^1.5.2"
85
+ "webpack-dev-server": "^4.7.2"
86
86
  },
87
87
  "packageManager": "yarn@3.2.3"
88
88
  }
package/scripts/start.js CHANGED
@@ -2,13 +2,29 @@ process.env.BABEL_ENV = 'development';
2
2
  process.env.NODE_ENV = 'development';
3
3
 
4
4
  const webpack = require( 'webpack' );
5
+ const config = require( '../helpers/package-config' );
6
+ const {unlinkSync, writeFile} = require( 'fs' );
5
7
  const WebpackDevServer = require( 'webpack-dev-server' );
6
8
  const configHelper = require( '../helpers/config' );
9
+ const path = require( 'path' );
7
10
  const webpackConfig = configHelper.getConfig( 'webpack.dev.js' );
8
11
  const devServerConfig = configHelper.getConfig( 'dev-server.config.js' );
9
12
 
10
13
  const server = new WebpackDevServer( devServerConfig, webpack( webpackConfig ) );
11
14
 
15
+ /**
16
+ * Create a `.running` file within the `dist` which only
17
+ * exists if this script is running.
18
+ */
19
+ writeFile( path.resolve( config.workingDirectory, 'dist/.running' ), Date.now().toString(), err => {
20
+ if ( err ) {
21
+ throw err;
22
+ }
23
+ process.on( 'exit', () => {
24
+ unlinkSync( path.resolve( config.workingDirectory, 'dist/.running' ) );
25
+ } );
26
+ } );
27
+
12
28
  ( async() => {
13
29
  try {
14
30
  await server.start();