diff --git a/packages/angular-cli/models/webpack-build-common.ts b/packages/angular-cli/models/webpack-build-common.ts
index 6130f887fbc0..18fe198247cd 100644
--- a/packages/angular-cli/models/webpack-build-common.ts
+++ b/packages/angular-cli/models/webpack-build-common.ts
@@ -52,13 +52,9 @@ export function getWebpackCommonConfig(
// 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(script.path);
- });
-
- // load global scripts using script-loader
- extraRules.push({
- include: globalScripts.map((script) => script.path), test: /\.js$/, loader: 'script-loader'
+ 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\');'));
}