M
M
Michael R.2018-10-10 18:52:54
webpack
Michael R., 2018-10-10 18:52:54

Saving webpack files in different folders?

Greetings!
The webpack docs have:

module.exports = {
  entry: {
    app: './src/app.js',
    search: './src/search.js'
  },
  output: {
    filename: '[name].js',
    path: __dirname + '/dist'
  }
};

It turns out that in entry you can specify the path to any file in src.
Question: what is the right way to specify paths to different folders in webpack 4 at the moment, for example, save app.js in /dist/app/, and search.js in /dist/search/?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael R., 2018-10-11
@Mike_Ro

Unfortunately - no way. You can only have one output path., but you can use multiple configs and export an array with these configs:

// webpack.config.js

const { join } = require('path');

const appConfig = {
    entry: './src/app.js',
    output: {
        filename: '[name].js',
        path: join(__dirname, 'dist/app')
    }
};

const searchConfig = {
    entry: './src/search.js',
    output: {
        filename: '[name].js',
        path: join(__dirname, 'dist/search')
    }
};

const common = {
    context: __dirname,

    module: {
        rules: [...]
    }
};

module.exports = [{
    ...common,
    ...appConfig
}, {
    ...common,
    ...searchConfig
}];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question