Add option to build with Webpack Bundle Analyzer (#2708)

* Add option to build with webpack bundle analyzer

* Bump npm to v7 as recommended in actions/setup-node#213

* Workaround for npm/cli#558

* Add missing dep
This commit is contained in:
David Wheatley 2021-04-10 15:00:48 +01:00 committed by GitHub
parent b1f166d82a
commit e52b769ceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 501 additions and 548 deletions

View File

@ -25,8 +25,12 @@ jobs:
with: with:
node-version: "14" node-version: "14"
- name: Use npm v7
run: sudo npm install -g npm@7.x.x
- name: Install JS dependencies - name: Install JS dependencies
run: npm ci # We need to use `npm install` here. If we don't, the workflow will fail.
run: npm install
working-directory: ./js working-directory: ./js
- name: Build production assets - name: Build production assets

1029
js/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -23,16 +23,19 @@
"@types/punycode": "^2.1.0", "@types/punycode": "^2.1.0",
"@types/textarea-caret": "^3.0.0", "@types/textarea-caret": "^3.0.0",
"bundlewatch": "^0.3.2", "bundlewatch": "^0.3.2",
"cross-env": "^7.0.3",
"flarum-webpack-config": "0.1.0-beta.10", "flarum-webpack-config": "0.1.0-beta.10",
"husky": "^4.3.8", "husky": "^4.3.8",
"prettier": "^2.2.1", "prettier": "^2.2.1",
"webpack": "^4.46.0", "webpack": "^4.46.0",
"webpack-bundle-analyzer": "^4.4.0",
"webpack-cli": "^3.3.12", "webpack-cli": "^3.3.12",
"webpack-merge": "^4.2.2" "webpack-merge": "^4.2.2"
}, },
"scripts": { "scripts": {
"dev": "webpack --mode development --watch", "dev": "webpack --mode development --watch",
"build": "webpack --mode production", "build": "webpack --mode production",
"analyze": "cross-env ANALYZER=true npm run build",
"format": "prettier --write src", "format": "prettier --write src",
"format-check": "prettier --check src" "format-check": "prettier --check src"
}, },

View File

@ -1,6 +1,15 @@
const config = require('flarum-webpack-config'); const config = require('flarum-webpack-config');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const merge = require('webpack-merge'); const merge = require('webpack-merge');
const useBundleAnalyzer = process.env.ANALYZER === 'true';
const plugins = [];
if (useBundleAnalyzer) {
plugins.push(new BundleAnalyzerPlugin());
}
module.exports = merge(config(), { module.exports = merge(config(), {
output: { output: {
library: 'flarum.core', library: 'flarum.core',
@ -10,6 +19,8 @@ module.exports = merge(config(), {
resolve: { resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'], extensions: ['.ts', '.tsx', '.js', '.json'],
}, },
plugins,
}); });
module.exports['module'].rules[0].test = /\.(tsx?|js)$/; module.exports['module'].rules[0].test = /\.(tsx?|js)$/;