aurelia / loader-webpack

An implementation of Aurelia's loader interface to enable webpack.
MIT License
26 stars 10 forks source link

Aurelia Plugin doesn't use Webpack "entry" items as expected #44

Closed silbinarywolf closed 5 years ago

silbinarywolf commented 5 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: Aurelia currently only prepends special runtime files to the first entry defined in your Webpack config file.

'aurelia-webpack-plugin/runtime/empty-entry',
'aurelia-webpack-plugin/runtime/pal-loader-entry',

Snippet from node_modules\aurelia-webpack-plugin\dist\AureliaPlugin.js

addEntry(options, modules) {
    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])
        });
    } else {
        options.entry = entries.concat(webpackEntry);
    }
}

Before Webpack 4, the fix/workaround above probably made sense. However, since vendoring is not handled in entry anymore, I think we can remove this without much fuss. I think ultimately it would help Aurelia be more predictable.

Making this change would require a major version bump as it breaks / changes behaviour.

addEntry(options, modules) {
    let webpackEntry = options.entry;
    let entries = Array.isArray(modules) ? modules : [modules];
    if (typeof webpackEntry == "object" && !Array.isArray(webpackEntry)) {
        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);
    }
}
silbinarywolf commented 5 years ago

Wrong repo. Moved here: https://github.com/aurelia/webpack-plugin/issues/157