Skip to content

Commit 676ae7f

Browse files
committed
native transform + keep names + dependency updates
1 parent e1b00ad commit 676ae7f

8 files changed

Lines changed: 42 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.9.0
4+
- Added babel native transform support and updated babelrc.
5+
- Added TerserPlugin with *--keep-names* cli option.
6+
- Updated dependencies.
7+
38
## 0.8.4
49
- Updated dependencies.
510

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 squirrel-forge
3+
Copyright (c) 2022 squirrel-forge
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ A long option always override the value of a short option if both are used.
4747
| -d | --development | bool | Development mode |
4848
| -p | --production | bool | Production mode |
4949
| | --no-minify | bool | Do not minify, sets the *optimization.minify* option to false |
50+
| | --keep-names | bool | Add terser with keep names options |
5051
| -e | --extend | bool/str | Extend the webpack config using *webpack-merge*, optionally specify a path, default: cwd/*extend.webpack.config.js* |
5152
| -b | --bundle | bool | Bundle all files in one entry |
5253
| -n | --name | str | Bundle name, default: 'bundle' |

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@squirrel-forge/simple-webpack",
3-
"version": "0.8.4",
3+
"version": "0.9.0",
44
"description": "A thin node wrapper for webpack with some basic options and configuration.",
55
"main": "src/classes/SimpleWebpack.js",
66
"scripts": {
@@ -33,18 +33,19 @@
3333
"node": ">= 10.0.0"
3434
},
3535
"dependencies": {
36-
"@babel/core": "^7.17.2",
36+
"@babel/core": "^7.17.9",
3737
"@babel/eslint-parser": "^7.17.0",
3838
"@babel/preset-env": "^7.16.11",
3939
"@squirrel-forge/node-cfx": "^1.2.1",
4040
"@squirrel-forge/node-util": "^1.4.2",
41-
"babel-loader": "^8.2.3",
41+
"babel-loader": "^8.2.4",
42+
"babel-plugin-transform-builtin-extend": "^1.1.2",
4243
"cli-spinner": "^0.2.10",
43-
"directory-tree": "^3.2.1",
44+
"directory-tree": "^3.2.2",
4445
"eslint": "^7.32.0",
4546
"eslint-webpack-plugin": "^3.1.1",
4647
"intercept-stdout": "^0.1.2",
47-
"webpack": "^5.68.0",
48+
"webpack": "^5.72.0",
4849
"webpack-bundle-analyzer": "^4.5.0",
4950
"webpack-merge": "^5.8.0"
5051
}

src/babelrc.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
[
44
"@babel/preset-env",
55
{
6-
"targets": {"browsers": [ "> 2%", "last 2 versions" ]},
6+
"targets": {"browsers": [ "> 2%", "last 2 versions", "not ie <= 11" ]},
77
"modules": false
88
}
99
]
10+
],
11+
"plugins": [
12+
[ "babel-plugin-transform-builtin-extend", {
13+
"globals": [ "Error" ]
14+
} ]
1015
]
1116
}

src/classes/SimpleWebpack.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const path = require( 'path' );
55
const webpack = require( 'webpack' );
66
const { merge } = require( 'webpack-merge' );
7+
const TerserPlugin = require( 'terser-webpack-plugin' );
78
const ESLintPlugin = require( 'eslint-webpack-plugin' );
89
const { BundleAnalyzerPlugin } = require( 'webpack-bundle-analyzer' );
910
const { Exception, Timer, FsInterface, isPojo } = require( '@squirrel-forge/node-util' );
@@ -265,6 +266,18 @@ class SimpleWebpack {
265266
optimization : { minimize : typeof options.minify === 'boolean' ? options.minify : this.production },
266267
};
267268

269+
// Add terser with keep names options
270+
if ( config.optimization.minimize && options.keepnames ) {
271+
config.optimization.minimizer = [
272+
new TerserPlugin( {
273+
terserOptions : {
274+
keep_classnames : true,
275+
keep_fnames : /^(?!_).+/,
276+
},
277+
} ),
278+
];
279+
}
280+
268281
// Add analyzer plugin if options available
269282
if ( this.analyzer ) {
270283

src/cli.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ module.exports = async function cli() {
6060
// Disable minification
6161
nominify : [ ' ', '--no-minify', false, true ],
6262

63+
// Disable minification
64+
keepnames : [ ' ', '--keep-names', false, true ],
65+
6366
// Extend config
6467
extend : [ '-e', '--extend', null, true, true ],
6568

@@ -204,6 +207,11 @@ module.exports = async function cli() {
204207
swpOptions.minify = false;
205208
}
206209

210+
// Terser keep names options
211+
if ( swpOptions.minify && options.keepnames ) {
212+
swpOptions.keepnames = true;
213+
}
214+
207215
// Load extend options
208216
if ( options.extend ) {
209217

src/eslintrc.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313

1414
"rules": {
15-
"strict": 2,
15+
"strict": [ 2, "global" ],
1616

1717
"for-direction": 2,
1818
"getter-return": 2,
@@ -86,9 +86,8 @@
8686
"template-curly-spacing": [ 2, "never" ],
8787
"yield-star-spacing": [ "error", { "before": true, "after": true } ],
8888

89-
"array-bracket-newline": [ 2, { "multiline": true, "minItems": 3 } ],
89+
"array-bracket-newline": [ 2, "consistent" ],
9090
"array-bracket-spacing": [ 2, "always"],
91-
"array-element-newline": [ 2, { "multiline": true, "minItems": 3 } ],
9291
"block-spacing" : 2,
9392
"brace-style": [ 2, "1tbs", { "allowSingleLine": true } ],
9493
"comma-dangle": [ 2, { "arrays": "only-multiline", "objects": "only-multiline", "imports": "never", "exports": "never", "functions": "ignore" } ],
@@ -112,7 +111,6 @@
112111
"no-trailing-spaces": 2,
113112
"no-unneeded-ternary": 2,
114113

115-
"object-curly-newline": [ 2, { "ObjectExpression": { "multiline": true, "minProperties": 8 }, "ObjectPattern": { "multiline": true, "minProperties": 8 }, "ImportDeclaration": { "multiline": true, "minProperties": 8 }, "ExportDeclaration": { "multiline": true, "minProperties": 8 } } ],
116114
"object-curly-spacing": [ 2, "always", { "arraysInObjects": true, "objectsInObjects": true } ],
117115
"one-var": [ 2, { "var": "always", "let": "consecutive", "const": "never" } ],
118116

0 commit comments

Comments
 (0)