M
M
Mike Khromov2015-11-13 11:55:07
webpack
Mike Khromov, 2015-11-13 11:55:07

Webpack, how to save to different directories?

There are two directories, for the mobile version of the site and for the normal one, in webpack, respectively, I made two entry points, but the output still turns out to be one, how can I separate the output files into directories?

var path = require('path');
var webpack = require('webpack');
var assets = 'project/assets/';

var config = {
  entry: {
    app: path.resolve(__dirname, assets + 'apps/add.js'),
    mobile: path.resolve(__dirname, assets + 'mobile/add.js')
  },
  output: {
    path: path.resolve(__dirname, assets + 'js'),
    filename: '/apps/[name].js'
  }
};

module.exports = config;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Kantor, 2015-11-14
@iliakan

Here you essentially have two independent assemblies, if I understand the intent correctly.
This is implemented through multiple compilation, that is, an array of configs:

var config = [{
  entry: ..
  output: ...
}, {
  entry: ..
  output: ...
}];

module.exports = config;

As a rule, they take one config as a base, and generate an array based on it, for example, changing the output directories, variables for DefinePlugin or something else in it.
Also, for webpack configs, this merge is convenient: https://github.com/survivejs/webpack-merge.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question