From 0f0bbc9dca2f1aab62771378aca43ae92f5c2d6b Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Sun, 1 Jan 2017 16:26:26 +0000 Subject: [PATCH] fix(scripts): allow using same lib inside app Fix #2141 --- packages/angular-cli/models/webpack-build-common.ts | 8 ++------ tests/e2e/tests/build/scripts-array.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/angular-cli/models/webpack-build-common.ts b/packages/angular-cli/models/webpack-build-common.ts index b7493d287c89..9e16d0c2a65e 100644 --- a/packages/angular-cli/models/webpack-build-common.ts +++ b/packages/angular-cli/models/webpack-build-common.ts @@ -57,13 +57,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\');')); }