Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 141cb23

Browse files
committed
feature(webpack): use a vendor bundle to minimize code that needs re-bundling and source map generation
1 parent 691d645 commit 141cb23

File tree

5 files changed

+32
-134
lines changed

5 files changed

+32
-134
lines changed

config/webpack.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
output: {
1010
path: '{{BUILD}}',
1111
publicPath: 'build/',
12-
filename: process.env.IONIC_OUTPUT_JS_FILE_NAME,
12+
filename: '[name].js',
1313
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
1414
},
1515
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
@@ -38,7 +38,8 @@ module.exports = {
3838

3939
plugins: [
4040
ionicWebpackFactory.getIonicEnvironmentPlugin(),
41-
new ModuleConcatPlugin()
41+
ionicWebpackFactory.getCommonChunksPlugin(),
42+
new ModuleConcatPlugin(),
4243
],
4344

4445
// Some libraries import Node modules but don't use them in the browser.
@@ -48,4 +49,4 @@ module.exports = {
4849
net: 'empty',
4950
tls: 'empty'
5051
}
51-
};
52+
};

package-lock.json

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/webpack/common-chunks-plugins.spec.ts

Lines changed: 0 additions & 78 deletions
This file was deleted.

src/webpack/common-chunks-plugins.ts

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,15 @@
1-
import { join } from 'path';
21
import * as CommonChunksPlugin from 'webpack/lib/optimize/CommonsChunkPlugin';
32

4-
export const NODE_MODULES = join(process.cwd(), 'node_modules');
5-
export const RXJS = join(NODE_MODULES, 'rxjs');
6-
export const ZONEJS = join(NODE_MODULES, 'zone.js');
7-
export const ANGULAR = join(NODE_MODULES, '@angular');
8-
export const IONIC = join(NODE_MODULES, 'ionic-angular');
3+
import * as Constants from '../util/constants';
4+
import { getStringPropertyValue } from '../util/helpers';
95

10-
export function getIonicDependenciesCommonChunksPlugin() {
6+
export function getCommonChunksPlugin() {
117
return new CommonChunksPlugin({
12-
name: 'known-vendors',
13-
minChunks: checkIfModuleIsIonicDependency
8+
name: 'vendor',
9+
minChunks: checkIfInNodeModules
1410
});
1511
}
1612

17-
export function getNonIonicDependenciesCommonChunksPlugin() {
18-
return new CommonChunksPlugin({
19-
name: 'unknown-vendors',
20-
minChunks: checkIfModuleIsNodeModuleButNotIonicDepenedency
21-
});
22-
}
23-
24-
function isIonicDependency(modulePath: string) {
25-
return modulePath.startsWith(RXJS) || modulePath.startsWith(ZONEJS) || modulePath.startsWith(ANGULAR) || modulePath.startsWith(IONIC);
26-
}
27-
28-
export function checkIfModuleIsIonicDependency(module: any) {
29-
return !!(module.userRequest && isIonicDependency(module.userRequest));
30-
}
31-
32-
export function checkIfModuleIsNodeModuleButNotIonicDepenedency(module: any) {
33-
return !!(module.userRequest && module.userRequest.startsWith(NODE_MODULES) && !isIonicDependency(module.userRequest));
13+
function checkIfInNodeModules(webpackModule: any) {
14+
return webpackModule && webpackModule.userRequest && webpackModule.userRequest.startsWith(getStringPropertyValue(Constants.ENV_VAR_NODE_MODULES_DIR));
3415
}

src/webpack/ionic-webpack-factory.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getIonicDependenciesCommonChunksPlugin, getNonIonicDependenciesCommonChunksPlugin } from './common-chunks-plugins';
1+
import { getCommonChunksPlugin } from './common-chunks-plugins';
22
import { IonicEnvironmentPlugin } from './ionic-environment-plugin';
33
import { provideCorrectSourcePath } from './source-mapper';
44
import { getContext } from '../util/helpers';
@@ -12,10 +12,4 @@ export function getSourceMapperFunction(): Function {
1212
return provideCorrectSourcePath;
1313
}
1414

15-
export function getNonIonicCommonChunksPlugin(): any {
16-
return getNonIonicDependenciesCommonChunksPlugin();
17-
}
18-
19-
export function getIonicCommonChunksPlugin(): any {
20-
return getIonicDependenciesCommonChunksPlugin();
21-
}
15+
export { getCommonChunksPlugin };

0 commit comments

Comments
 (0)