-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular/cli): support sourcemaps and minification in scripts
Adds sourcemap and minification to javascript added via the `scripts` array in `.angular-cli.json`. `script-loader` is no longer used, which should help with CSP since it used `eval`. Scripts will no longer appear in the console output for `ng build`, as they are now assets instead of webpack entry points. It's no longer possible to have the `output` property of both a `scripts` and a `styles` entry pointing to the same file. This wasn't officially supported or listed in the docs, but used to be possible. Fix #2796 Fix #7226 Fix #7290 Related to #6872
- Loading branch information
1 parent
b9a62e0
commit e8f27f0
Showing
12 changed files
with
202 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/@angular/cli/plugins/insert-concat-assets-webpack-plugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Add assets from `ConcatPlugin` to index.html. | ||
|
||
export class InsertConcatAssetsWebpackPlugin { | ||
// Priority list of where to insert asset. | ||
private insertAfter = [ | ||
/polyfills(\.[0-9a-f]{20})?\.bundle\.js/, | ||
/inline(\.[0-9a-f]{20})?\.bundle\.js/, | ||
]; | ||
|
||
constructor(private entryNames: string[]) { } | ||
|
||
apply(compiler: any): void { | ||
compiler.plugin('compilation', (compilation: any) => { | ||
compilation.plugin('html-webpack-plugin-before-html-generation', | ||
(htmlPluginData: any, callback: any) => { | ||
|
||
const fileNames = this.entryNames.map((entryName) => { | ||
const fileName = htmlPluginData.assets.webpackConcat | ||
&& htmlPluginData.assets.webpackConcat[entryName]; | ||
|
||
if (!fileName) { | ||
// Something went wrong and the asset was not correctly added. | ||
throw new Error(`Cannot find file for ${entryName} script.`); | ||
} | ||
|
||
return fileName; | ||
}); | ||
|
||
let insertAt = 0; | ||
|
||
// TODO: try to figure out if there are duplicate bundle names when adding and throw | ||
for (let el of this.insertAfter) { | ||
const jsIdx = htmlPluginData.assets.js.findIndex((js: string) => js.match(el)); | ||
if (jsIdx !== -1) { | ||
insertAt = jsIdx + 1; | ||
break; | ||
} | ||
} | ||
|
||
htmlPluginData.assets.js.splice(insertAt, 0, ...fileNames); | ||
callback(null, htmlPluginData); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.