electron-userland / electron-webpack

Scripts and configurations to compile Electron applications using webpack
https://webpack.electron.build/
905 stars 171 forks source link

Uncaught ReferenceError: vendor is not defined when using dll #15

Open ashokgelal opened 7 years ago

ashokgelal commented 7 years ago

As per your suggestion, I'm using dll to improve the build time but I get Uncaught ReferenceError: vendor is not defined error every time. With my experience with Laravel Mix I understand that I need to load the generated vendor.js file in dist/render-dll directoy but couldn't figure out how. I thought that this was automated and gets injected by electron-webpack.

I'm using electron-vue and my package.json looks something like this:

...
"files": [
      "dist/electron/**/*",
      "!node_modules/deep-diff/releases{,/**/*}",
      "!node_modules/bluebird/js/browser{,/**/*}",
      "!node_modules/source-map-support/**/*",
      "node_modules/source-map-support/source-map-support.js"
    ],
"electronWebpack": {
    "renderer": {
      "dll": [
        "vue",
        "vue-router",
        "vuex",
        "element-ui"
      ]
    }
  },
...

Thanks for your help.

develar commented 7 years ago

Do you have "postinstall": "electron-webpack dll" ?

Maybe you use custom HTML?

ashokgelal commented 7 years ago

Yes I do have "postintall": "electron-webpack dll"

Also, now I'm getting a different error when I run electron-webpack dll:

Error: DllPlugin: supply an Array as entry Similar to this: https://github.com/chentsulin/electron-react-boilerplate/issues/1199

loopmode commented 7 years ago

I have the same issue. Debugging it, I found that in webpack/lib/DLLPlugin (webpack@3.6.0), there is this code:

        compiler.plugin("entry-option", (context, entry) => {
                    function itemToPlugin(item, name) {
                if(Array.isArray(item))
                    return new DllEntryPlugin(context, item, name);
                else
                    throw new Error("DllPlugin: supply an Array as entry");
            }
            if(typeof entry === "object" && !Array.isArray(entry)) {
                Object.keys(entry).forEach(name => {
                    compiler.apply(itemToPlugin(entry[name], name));
                });
            } else {
                compiler.apply(itemToPlugin(entry, "main"));
            }
            return true;
        });

EDIT: Logging via console.log('DllPlugin', {item}) inside function itemToPlugin(item, name) we can see this:

DllPlugin { item: [ 'classnames', 'autobind-decorator' ] }
DllPlugin { item: 'dll' }

The problem is that dll ends up in there as a string, which is not an array..

This is probably due to entry coming in as { vendor: [ 'classnames', 'autobind-decorator' ], main: 'dll' }