Skip to content

Commit 5b2df93

Browse files
clydindond2clouds
authored andcommitted
refactor(@angular/cli): add webpack integrated scripts plugin
1 parent b1cdb6b commit 5b2df93

File tree

10 files changed

+186
-163
lines changed

10 files changed

+186
-163
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
"uglifyjs-webpack-plugin": "~1.1.2",
9696
"url-loader": "^0.6.2",
9797
"webpack": "~3.10.0",
98-
"webpack-concat-plugin": "^1.4.2",
9998
"webpack-dev-middleware": "~1.12.0",
10099
"webpack-dev-server": "~2.9.3",
101100
"webpack-merge": "^4.1.0",
@@ -116,13 +115,15 @@
116115
"@types/glob": "^5.0.29",
117116
"@types/jasmine": "2.5.45",
118117
"@types/lodash": "~4.14.50",
118+
"@types/loader-utils": "^1.1.0",
119119
"@types/minimist": "^1.2.0",
120120
"@types/mock-fs": "^3.6.30",
121121
"@types/node": "^6.0.84",
122122
"@types/request": "~2.0.0",
123123
"@types/semver": "^5.3.30",
124124
"@types/source-map": "^0.5.0",
125125
"@types/webpack": "^3.0.5",
126+
"@types/webpack-sources": "^0.1.3",
126127
"conventional-changelog": "1.1.0",
127128
"dtsgenerator": "^0.9.1",
128129
"eslint": "^3.11.0",

packages/@angular/cli/models/webpack-configs/common.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import * as webpack from 'webpack';
22
import * as path from 'path';
33
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
44
import { NamedLazyChunksWebpackPlugin } from '../../plugins/named-lazy-chunks-webpack-plugin';
5-
import { InsertConcatAssetsWebpackPlugin } from '../../plugins/insert-concat-assets-webpack-plugin';
65
import { extraEntryParser, getOutputHashFormat, AssetPattern } from './utils';
76
import { isDirectory } from '../../utilities/is-directory';
87
import { requireProjectModule } from '../../utilities/require-project-module';
98
import { WebpackConfigOptions } from '../webpack-config';
9+
import { ScriptsWebpackPlugin } from '../../plugins/scripts-webpack-plugin';
1010

11-
const ConcatPlugin = require('webpack-concat-plugin');
1211
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
1312
const CircularDependencyPlugin = require('circular-dependency-plugin');
1413
const SilentError = require('silent-error');
@@ -65,23 +64,16 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
6564

6665
// Add a new asset for each entry.
6766
globalScriptsByEntry.forEach((script) => {
68-
const hash = hashFormat.chunk !== '' && !script.lazy ? '.[hash]' : '';
69-
extraPlugins.push(new ConcatPlugin({
70-
uglify: buildOptions.target === 'production' ? { sourceMapIncludeSources: true } : false,
71-
sourceMap: buildOptions.sourcemaps,
67+
// Lazy scripts don't get a hash, otherwise they can't be loaded by name.
68+
const hash = script.lazy ? '' : hashFormat.script;
69+
extraPlugins.push(new ScriptsWebpackPlugin({
7270
name: script.entry,
73-
// Lazy scripts don't get a hash, otherwise they can't be loaded by name.
74-
fileName: `[name]${script.lazy ? '' : hash}.bundle.js`,
75-
filesToConcat: script.paths
71+
sourceMap: buildOptions.sourcemaps,
72+
filename: `${script.entry}${hash}.bundle.js`,
73+
scripts: script.paths,
74+
basePath: projectRoot,
7675
}));
7776
});
78-
79-
// Insert all the assets created by ConcatPlugin in the right place in index.html.
80-
extraPlugins.push(new InsertConcatAssetsWebpackPlugin(
81-
globalScriptsByEntry
82-
.filter((el) => !el.lazy)
83-
.map((el) => el.entry)
84-
));
8577
}
8678

8779
// process asset entries

packages/@angular/cli/models/webpack-configs/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ export function getOutputHashFormat(option: string, length = 20): HashFormat {
8181
const hashFormats: { [option: string]: HashFormat } = {
8282
none: { chunk: '', extract: '', file: '' , script: '' },
8383
media: { chunk: '', extract: '', file: `.[hash:${length}]`, script: '' },
84-
bundles: { chunk: `.[chunkhash:${length}]`, extract: `.[contenthash:${length}]`, file: '' , script: '.[hash]' },
85-
all: { chunk: `.[chunkhash:${length}]`, extract: `.[contenthash:${length}]`, file: `.[hash:${length}]`, script: '.[hash]' },
84+
bundles: { chunk: `.[chunkhash:${length}]`, extract: `.[contenthash:${length}]`, file: '' , script: `.[hash:${length}]` },
85+
all: { chunk: `.[chunkhash:${length}]`, extract: `.[contenthash:${length}]`, file: `.[hash:${length}]`, script: `.[hash:${length}]` },
8686
};
8787
/* tslint:enable:max-line-length */
8888
return hashFormats[option] || hashFormats['none'];

packages/@angular/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"less-loader": "^4.0.5",
5454
"license-webpack-plugin": "^1.0.0",
5555
"lodash": "^4.11.1",
56+
"loader-utils": "1.1.0",
5657
"memory-fs": "^0.4.1",
5758
"minimatch": "^3.0.4",
5859
"node-modules-path": "^1.0.0",
@@ -77,7 +78,6 @@
7778
"uglifyjs-webpack-plugin": "~1.1.2",
7879
"url-loader": "^0.6.2",
7980
"webpack": "~3.10.0",
80-
"webpack-concat-plugin": "^1.4.2",
8181
"webpack-dev-middleware": "~1.12.0",
8282
"webpack-dev-server": "~2.9.3",
8383
"webpack-merge": "^4.1.0",

packages/@angular/cli/plugins/insert-concat-assets-webpack-plugin.ts

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

0 commit comments

Comments
 (0)