aurelia / webpack-plugin

A plugin for webpack that enables bundling Aurelia applications.
MIT License
90 stars 36 forks source link

Cannot put resources from external module into non-app bundle #76

Closed smax48 closed 7 years ago

smax48 commented 8 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: I am using aurelia-kendoui-bridge 1.0.0-beta.1.0.13 and want to bundle all it's resources into a separate bundle (with the name "vendors"). The bridge itself has it's own "aurelia/build/resources" section with common resources. For some reason, they are bundled into the app bundle, not the bundle for the bridge that I specified. Non-resource bridge's components (referenced from its main) are bundled correctly into the "vendors" bundle. If I specify additional resources from the bridge (either in the resources section of my app or using ) - they also go into the app bundle. If I specify resources in the form:

{"path": "aurelia-kendoui-bridge/window/window",  "bundle": "vendors"}        

Then I get the following error on npm run build:

ERROR in CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk (vendors)

I started off my project from the latest aurelia-webpack-typescript skeleton. Extract from my webpack config:

const baseConfig = {
  entry: {
    'app': [/* this is filled by the aurelia-webpack-plugin */],
    'aurelia-bootstrap': coreBundles.bootstrap,
    'aurelia': coreBundles.aurelia.filter(pkg => coreBundles.bootstrap.indexOf(pkg) === -1),
    'vendors': ['aurelia-kendoui-bridge']
  },
  output: {
    path: outDir,
  }   
}

Expected/desired behavior: All external module's resources are bundled together with that module in the specified bundle

niieani commented 8 years ago

You might need to configure CommonsChunkPlugin differently. Does the same error occur when you make the entry chunk vendors empty?: 'vendors': []

smax48 commented 8 years ago

I would like to if I knew how exactly differently :) Yes, when I make the vendors chunk empty, I get the same error. Interestingly, that the bundles are generated and my app bundle contains all resources from the bridge that are specified in both my app project.json (despite the "bundle" property) and in the bridge's...

niieani commented 8 years ago

I'll look into this, but can't promise a timeframe. Try reading up on CommonChunksPlugin, I'm not sure if the default config from easy-webpack handles this use case. As a workaround, try lazy-loading the resources instead of specifying a separate entry bundle:

{"path": "aurelia-kendoui-bridge", "bundle": "vendors", "lazy": true}

Might need to be done for the sub-resources too, not sure.

smax48 commented 8 years ago

Thanks! I will try different configuration options for CommonChunksPlugin. The problem is that I don't know what aurelia-webpack plugin does with resources defined in package.json of external modules (in my case, aurelia-kendoui-bridge) - at the moment they are bundled with app code for some reason...

smax48 commented 8 years ago

Unfortunately, I was unable to configure CommonsChunkPlugin in the way that it puts all aurelia-kendoui-bridge resources into a non-app bundle. I tried a lot of different configuration variants, but result was always the same (either resources end up in the app chunk or I get "ERROR in CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk").

It seems that the "bundle" property for aurelia resources just doesn't work in the case of non-lazy resources.

Your workaround does produce a separate chunk with resources, but the app crashes at runtime when it tries to load it...

niieani commented 7 years ago

Fixed by https://github.com/aurelia/skeleton-navigation/pull/714