2018-03-05 23:03:12 +01:00
|
|
|
const Path = require('path');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
// Import the core config
|
|
|
|
const webpackConfig = require('@silverstripe/webpack-config');
|
|
|
|
const {
|
|
|
|
resolveJS,
|
|
|
|
externalJS,
|
|
|
|
moduleJS,
|
|
|
|
pluginJS,
|
|
|
|
moduleCSS,
|
|
|
|
pluginCSS,
|
|
|
|
} = webpackConfig;
|
2018-02-01 08:39:53 +01:00
|
|
|
|
2018-03-05 23:03:12 +01:00
|
|
|
const ENV = process.env.NODE_ENV;
|
2018-02-01 08:39:53 +01:00
|
|
|
const PATHS = {
|
2018-03-05 23:03:12 +01:00
|
|
|
// the root path, where your webpack.config.js is located.
|
|
|
|
ROOT: Path.resolve(),
|
|
|
|
// your node_modules folder name, or full path
|
|
|
|
MODULES: 'node_modules',
|
|
|
|
// relative path from your css files to your other files, such as images and fonts
|
|
|
|
FILES_PATH: '../',
|
|
|
|
// the root path to your javascript source files
|
|
|
|
SRC: Path.resolve('client/src'),
|
|
|
|
DIST: Path.resolve('client/dist'),
|
2018-02-01 08:39:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const config = [
|
|
|
|
{
|
|
|
|
name: 'js',
|
2018-08-16 14:45:17 +02:00
|
|
|
entry: {
|
|
|
|
main: `${PATHS.SRC}/bundles/bundle.js`,
|
|
|
|
},
|
2018-02-01 08:39:53 +01:00
|
|
|
output: {
|
|
|
|
path: PATHS.DIST,
|
2018-03-05 23:03:12 +01:00
|
|
|
filename: 'js/[name].js',
|
2018-02-01 08:39:53 +01:00
|
|
|
},
|
2018-03-05 23:03:12 +01:00
|
|
|
devtool: (ENV !== 'production') ? 'source-map' : '',
|
|
|
|
resolve: resolveJS(ENV, PATHS),
|
|
|
|
externals: externalJS(ENV, PATHS),
|
|
|
|
module: moduleJS(ENV, PATHS),
|
|
|
|
plugins: pluginJS(ENV, PATHS),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'css',
|
2018-08-16 14:45:17 +02:00
|
|
|
entry: {
|
|
|
|
main: `${PATHS.SRC}/styles/bundle.scss`,
|
|
|
|
},
|
2018-02-01 08:39:53 +01:00
|
|
|
output: {
|
|
|
|
path: PATHS.DIST,
|
2018-03-05 23:03:12 +01:00
|
|
|
filename: 'styles/[name].css'
|
2018-02-01 08:39:53 +01:00
|
|
|
},
|
|
|
|
devtool: (ENV !== 'production') ? 'source-map' : '',
|
2018-03-05 23:03:12 +01:00
|
|
|
module: moduleCSS(ENV, PATHS),
|
|
|
|
plugins: pluginCSS(ENV, PATHS),
|
|
|
|
},
|
2018-02-01 08:39:53 +01:00
|
|
|
];
|
|
|
|
|
2018-08-16 14:45:17 +02:00
|
|
|
// Use WEBPACK_CHILD=js or WEBPACK_CHILD=css env var to run a single config
|
|
|
|
module.exports = (process.env.WEBPACK_CHILD)
|
|
|
|
? config.find((entry) => entry.name === process.env.WEBPACK_CHILD)
|
|
|
|
: module.exports = config;
|