Skip to content

Commit

Permalink
Merge pull request #159 from silbinarywolf/fix/remove-entry-hack-v2
Browse files Browse the repository at this point in the history
fix(webpack): remove runtime insertion hack from webpack 3 or below e…
  • Loading branch information
EisenbergEffect authored May 1, 2019
2 parents 2743730 + 2c05e08 commit 9db5541
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/AureliaPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,30 @@ export class AureliaPlugin {
addEntry(options: Webpack.Options, modules: string|string[]) {
let webpackEntry = options.entry;
let entries = Array.isArray(modules) ? modules : [modules];
if (typeof webpackEntry == "object" && !Array.isArray(webpackEntry)) {
// There are multiple entries defined in the config
// Unless there was a particular configuration, we modify the first one
// (note that JS enumerates props in the same order they were declared)
// Modifying the first one only plays nice with the common pattern
// `entry: { main, vendor }` some people use.
let ks = this.options.entry || Object.keys(webpackEntry)[0];
if (!Array.isArray(ks)) ks = [ks];
ks.forEach(k => webpackEntry[k] = entries.concat(webpackEntry[k]));
if (typeof webpackEntry === "object" && !Array.isArray(webpackEntry)) {
if (this.options.entry) {
// Add runtime only to the entries defined on this plugin
let ks = this.options.entry;
if (!Array.isArray(ks)) ks = [ks];
ks.forEach(k => {
if (webpackEntry[k] === undefined) {
throw new Error('entry key "' + k + '" is not defined in Webpack build, cannot apply runtime.');
}
webpackEntry[k] = entries.concat(webpackEntry[k])
});
} else {
// Add runtime to each entry
for (let k in webpackEntry) {
if (!webpackEntry.hasOwnProperty(k)) {
continue;
}
let entry = webpackEntry[k];
if (!Array.isArray(entry)) {
entry = [entry];
}
webpackEntry[k] = entries.concat(entry);
}
}
}
else
options.entry = entries.concat(webpackEntry);
Expand Down

0 comments on commit 9db5541

Please sign in to comment.