Skip to content

Commit 58dfe8d

Browse files
committed
build: add option to disable core-js polyfill
Pass env `no-core-js` to replace `core-js` with a dummy module, decreasing the bundle size by 40k+.
1 parent f3aaff5 commit 58dfe8d

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

build/dummy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {}

webpack.config.js

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,40 @@ const BuildTarget = ['web', 'wx'];
99
module.exports = (env, argv) => {
1010
const isDev = argv.mode === 'development';
1111
const __TARGET__ = BuildTarget.indexOf(env.target) === -1 ? BuildTarget[0] : env.target;
12+
const noCoreJS = !!env['no-core-js']
13+
// define plugins
14+
const plugins = [
15+
new Webpack.BannerPlugin({
16+
banner: [
17+
'vConsole v' + pkg.version + ' (' + pkg.homepage + ')',
18+
'',
19+
'Tencent is pleased to support the open source community by making vConsole available.',
20+
'Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.',
21+
'Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at',
22+
'http://opensource.org/licenses/MIT',
23+
'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.',
24+
].join('\n'),
25+
entryOnly: true,
26+
}),
27+
new Webpack.DefinePlugin({
28+
__VERSION__: JSON.stringify(pkg.version),
29+
__TARGET__: JSON.stringify(__TARGET__),
30+
}),
31+
];
32+
if (isDev) {
33+
plugins.push({
34+
apply: (compiler) => {
35+
compiler.hooks.done.tap('DeclarationEmitter', () => {
36+
execSync('npm run build:typings');
37+
});
38+
},
39+
})
40+
}
41+
if (noCoreJS) {
42+
const dummyModulePath = Path.resolve(__dirname, './build/dummy.js');
43+
plugins.push(new Webpack.NormalModuleReplacementPlugin(/^core-js\/.*/, dummyModulePath));
44+
}
45+
1246
return {
1347
mode: argv.mode,
1448
devtool: false,
@@ -108,31 +142,6 @@ module.exports = (env, argv) => {
108142
watchOptions: {
109143
ignored: ['**/node_modules'],
110144
},
111-
plugins: [
112-
new Webpack.BannerPlugin({
113-
banner: [
114-
'vConsole v' + pkg.version + ' (' + pkg.homepage + ')',
115-
'',
116-
'Tencent is pleased to support the open source community by making vConsole available.',
117-
'Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.',
118-
'Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at',
119-
'http://opensource.org/licenses/MIT',
120-
'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.',
121-
].join('\n'),
122-
entryOnly: true,
123-
}),
124-
new Webpack.DefinePlugin({
125-
__VERSION__: JSON.stringify(pkg.version),
126-
__TARGET__: JSON.stringify(__TARGET__),
127-
}),
128-
{
129-
apply: (compiler) => {
130-
compiler.hooks.done.tap('DeclarationEmitter', () => {
131-
if (isDev) return; // only emit declarations in prod mode
132-
execSync('npm run build:typings');
133-
});
134-
},
135-
},
136-
],
145+
plugins
137146
};
138147
};

0 commit comments

Comments
 (0)