Skip to content

Commit 0f0bbc9

Browse files
committed
fix(scripts): allow using same lib inside app
Fix #2141
1 parent 74f7cdd commit 0f0bbc9

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/angular-cli/models/webpack-build-common.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,9 @@ export function getWebpackCommonConfig(
5757

5858
// add entry points and lazy chunks
5959
globalScripts.forEach(script => {
60+
let scriptPath = `script-loader!${script.path}`;
6061
if (script.lazy) { lazyChunks.push(script.entry); }
61-
entryPoints[script.entry] = (entryPoints[script.entry] || []).concat(script.path);
62-
});
63-
64-
// load global scripts using script-loader
65-
extraRules.push({
66-
include: globalScripts.map((script) => script.path), test: /\.js$/, loader: 'script-loader'
62+
entryPoints[script.entry] = (entryPoints[script.entry] || []).concat(scriptPath);
6763
});
6864
}
6965

tests/e2e/tests/build/scripts-array.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
writeMultipleFiles,
3-
expectFileToMatch
3+
expectFileToMatch,
4+
appendToFile
45
} from '../../utils/fs';
56
import { ng } from '../../utils/process';
67
import { updateJsonFile } from '../../utils/project';
@@ -16,6 +17,7 @@ export default function () {
1617
'src/common-entry-script.js': 'console.log(\'common-entry-script\');',
1718
'src/common-entry-style.css': '.common-entry-style { color: red }',
1819
})
20+
.then(() => appendToFile('src/main.ts', 'import \'./string-script.js\';'))
1921
.then(() => updateJsonFile('angular-cli.json', configJson => {
2022
const app = configJson['apps'][0];
2123
app['scripts'] = [
@@ -48,5 +50,7 @@ export default function () {
4850
<script type="text/javascript" src="scripts.bundle.js"></script>
4951
<script type="text/javascript" src="vendor.bundle.js"></script>
5052
<script type="text/javascript" src="main.bundle.js"></script>
51-
`));
53+
`))
54+
// ensure scripts aren't using script-loader when imported from the app
55+
.then(() => expectFileToMatch('dist/main.bundle.js', 'console.log(\'string-script\');'));
5256
}

0 commit comments

Comments
 (0)