0

I'm learning webpack and trying to set up multiple outputs (to also copy html files from src to dist, haven't added html config json yet). I'm getting an error 'output.filename is required' when I run webpack with this webpack.config.js. What am I missing?

    const path = require('path');

var sharedConfig = { // shared 
    module: {},
} // config

var jsConfig = Object.assign({},sharedConfig,{ // target(new empty object), copy members from, copy members from

    entry: {
        'page1': './src/page1/index.js',
        'page2': './src/page2/index.js',
        'widget1': './src/widget1/index.js',
        'widget2': './src/widget2/index.js'
    },
    output: {
        filename: '[name].bundle.js',
        path: path.join(__dirname, "dist")
    }

}); // assign

var htmlConfig = Object.assign({},sharedConfig,{ // target(new empty object), copy members from, copy members from

    entry: {
        'page1': './src/page1/index.html',
        'page2': './src/page2/index.html',
        'widget1': './src/widget1/index.html',
        'widget2': './src/widget2/index.html'
    },
    output: {
        filename: '[name].html',
        path: path.join(__dirname, "dist")
    }

}); // assign

module.exports = {jsConfig, htmlConfig};
Ted Fitzpatrick
  • 910
  • 1
  • 8
  • 18
  • replace the module.exports to: `module.exports = jsConfig`. Webpack does not know how to interpret webpack configs that are inside objects when this is read. – PlayMa256 Jul 17 '18 at 17:06
  • Hi Matheus, I added htmlConfig to better show my goal: I want to specify a separate entry+output for html. – Ted Fitzpatrick Jul 17 '18 at 17:19
  • I found this technique here on SO: https://stackoverflow.com/questions/32155154/webpack-config-how-to-just-copy-the-index-html-to-the-dist-folder HOWEVER I'm starting to rethink the goal, maybe I don't even need the html in the src folder, it's ok to have it only in the dist – Ted Fitzpatrick Jul 17 '18 at 17:24

1 Answers1

0

I've decided to not have html in my src folder, there's no need. My html will contain links to the js in my dist folder.

Ted Fitzpatrick
  • 910
  • 1
  • 8
  • 18