Skip to content

Commit

Permalink
fix(scripts): allow using same lib inside app (#3814)
Browse files Browse the repository at this point in the history
Fix #2141
  • Loading branch information
filipesilva authored and hansl committed Jan 20, 2017
1 parent f4b5773 commit a2ea05e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
15 changes: 5 additions & 10 deletions packages/angular-cli/models/webpack-build-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
8 changes: 6 additions & 2 deletions tests/e2e/tests/build/scripts-array.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
writeMultipleFiles,
expectFileToMatch
expectFileToMatch,
appendToFile
} from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
Expand All @@ -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'] = [
Expand Down Expand Up @@ -48,5 +50,7 @@ export default function () {
<script type="text/javascript" src="scripts.bundle.js"></script>
<script type="text/javascript" src="vendor.bundle.js"></script>
<script type="text/javascript" src="main.bundle.js"></script>
`));
`))
// ensure scripts aren't using script-loader when imported from the app
.then(() => expectFileToMatch('dist/main.bundle.js', 'console.log(\'string-script\');'));
}

0 comments on commit a2ea05e

Please sign in to comment.