0

In webpack, I am trying to achieve this:

entry: {
    test-1: './src/test-1/main.js',
    test-2: './src/test-2/main.js',
    test-3: './src/test-3/main.js'
},
...

However, it not possible to have a hyphen. My only solution to achieve this is to do something liket that ?

entry['test-1'] = './src/test-1/main.js';
entry['test-2'] = './src/test-2/main.js';
entry['test-3'] = './src/test-3/main.js';
PierBJX
  • 2,093
  • 5
  • 19
  • 50

2 Answers2

4

Adding the quotes around the keys fixes your issue.

webpack.config.js:

const path = require('path');

module.exports = {
  entry: {
      'test-1': './src/test-1.js',
      'test-2': './src/test-2.js',
  },
  output: {
    filename: '[name].js',
    path: path.resolve(__dirname, 'dist')
  }
};
meyi
  • 7,574
  • 1
  • 15
  • 28
0

You can use the following:

entry: {
    ['test-1']: './src/test-1/main.js',
    ['test-2']: './src/test-2/main.js',
    ['test-3']: './src/test-3/main.js'
},
...
dospro
  • 450
  • 1
  • 5
  • 17
  • 1
    Oh right. webpack config files don't support ES6. There are some work-arounds like described here https://stackoverflow.com/questions/33549895/i-cant-use-es6-in-webpack-config-file?noredirect=1&lq=1 , but most of them are worse than just using your own approach. – dospro Jun 19 '19 at 20:48
  • Thanks but I think @meyi's answer is better way to do it – PierBJX Jun 19 '19 at 20:55