diff --git a/packages/angular-cli/models/webpack-build-common.ts b/packages/angular-cli/models/webpack-build-common.ts
index 7d6b857bb187..ae2d05e698cd 100644
--- a/packages/angular-cli/models/webpack-build-common.ts
+++ b/packages/angular-cli/models/webpack-build-common.ts
@@ -59,16 +59,11 @@ export function getWebpackCommonConfig(
if (appConfig.scripts.length > 0) {
const globalScripts = extraEntryParser(appConfig.scripts, appRoot, 'scripts');
- // add script entry points
- globalScripts.forEach(script =>
- entryPoints[script.entry]
- ? entryPoints[script.entry].push(script.path)
- : entryPoints[script.entry] = [script.path]
- );
-
- // load global scripts using script-loader
- extraRules.push({
- include: globalScripts.map((script) => script.path), test: /\.js$/, loader: 'script-loader'
+ // add entry points and lazy chunks
+ globalScripts.forEach(script => {
+ let scriptPath = `script-loader!${script.path}`;
+ if (script.lazy) { lazyChunks.push(script.entry); }
+ entryPoints[script.entry] = (entryPoints[script.entry] || []).concat(scriptPath);
});
}
diff --git a/tests/e2e/tests/build/scripts-array.ts b/tests/e2e/tests/build/scripts-array.ts
index 7aad2420831b..f3d2a02ac34e 100644
--- a/tests/e2e/tests/build/scripts-array.ts
+++ b/tests/e2e/tests/build/scripts-array.ts
@@ -1,6 +1,7 @@
import {
writeMultipleFiles,
- expectFileToMatch
+ expectFileToMatch,
+ appendToFile
} from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
@@ -16,6 +17,7 @@ export default function () {
'src/common-entry-script.js': 'console.log(\'common-entry-script\');',
'src/common-entry-style.css': '.common-entry-style { color: red }',
})
+ .then(() => appendToFile('src/main.ts', 'import \'./string-script.js\';'))
.then(() => updateJsonFile('angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['scripts'] = [
@@ -48,5 +50,7 @@ export default function () {
- `));
+ `))
+ // ensure scripts aren't using script-loader when imported from the app
+ .then(() => expectFileToMatch('dist/main.bundle.js', 'console.log(\'string-script\');'));
}