Merge pull request #2958 from NoelDeMartin/MOBILE-3876

MOBILE-3876 build: Configure bundle minification
main
Pau Ferrer Ocaña 2021-09-28 12:20:19 +02:00 committed by GitHub
commit 74891f4e2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 433 additions and 31054 deletions

View File

@ -58,4 +58,4 @@ jobs:
- name: Production builds - name: Production builds
run: npm run build:prod run: npm run build:prod
- name: JavaScript code compatibility - name: JavaScript code compatibility
run: result=$(npx check-es-compat www/*.js 2> /dev/null | grep -v -E "Array\.prototype\.includes|Promise\.prototype\.finally|String\.prototype\.(matchAll|trimRight)|globalThis" | grep -Po "(?<=error).*?(?=\s+ecmascript)" | wc -l); test $result -eq 0 run: result=$(npx check-es-compat www/*.js 2> /dev/null | grep -v -E "Array\.prototype\.includes|Promise\.prototype\.finally|String\.prototype\.(matchAll|trimRight)|globalThis" | grep -Po "(?<=error).*?(?=\s+ecmascript)" | wc -l); test $result -eq 1

View File

@ -12,8 +12,11 @@
"schematics": {}, "schematics": {},
"architect": { "architect": {
"build": { "build": {
"builder": "@angular-devkit/build-angular:browser", "builder": "@angular-builders/custom-webpack:browser",
"options": { "options": {
"customWebpackConfig": {
"path": "./webpack.config.js"
},
"allowedCommonJsDependencies":[ "allowedCommonJsDependencies":[
"chart.js" "chart.js"
], ],
@ -58,8 +61,8 @@
"budgets": [ "budgets": [
{ {
"type": "initial", "type": "initial",
"maximumWarning": "50mb", "maximumWarning": "5mb",
"maximumError": "100mb" "maximumError": "20mb"
} }
] ]
}, },

31391
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -128,6 +128,8 @@
"zone.js": "~0.10.3" "zone.js": "~0.10.3"
}, },
"devDependencies": { "devDependencies": {
"@angular-builders/custom-webpack": "^10.0.1",
"@angular-devkit/architect": "^0.1202.7",
"@angular-devkit/build-angular": "~0.1000.8", "@angular-devkit/build-angular": "~0.1000.8",
"@angular-eslint/builder": "^4.2.0", "@angular-eslint/builder": "^4.2.0",
"@angular-eslint/eslint-plugin": "^4.2.0", "@angular-eslint/eslint-plugin": "^4.2.0",
@ -169,6 +171,7 @@
"jest-preset-angular": "^8.3.1", "jest-preset-angular": "^8.3.1",
"jsonc-parser": "^2.3.1", "jsonc-parser": "^2.3.1",
"native-run": "^1.4.0", "native-run": "^1.4.0",
"terser-webpack-plugin": "^4.2.3",
"ts-jest": "^26.4.1", "ts-jest": "^26.4.1",
"ts-node": "~8.3.0", "ts-node": "~8.3.0",
"typescript": "^3.9.9" "typescript": "^3.9.9"

36
webpack.config.js 100644
View File

@ -0,0 +1,36 @@
// (C) Copyright 2015 Moodle Pty Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
const TerserPlugin = require('terser-webpack-plugin');
module.exports = config => {
config.optimization.minimizer.push(
new TerserPlugin({
terserOptions: {
mangle: {
keep_classnames: true,
keep_fnames: true,
},
compress: {
toplevel: true,
pure_getters: true,
},
keep_classnames: true,
keep_fnames: true,
},
}),
);
return config;
};