require('require-yaml'); const webpack = require('webpack'); const path = require('path'); const merge = require('webpack-merge'); const AssetsWebpackPlugin = require('assets-webpack-plugin'); const wpConfig = require('./webpack.config.yml'); let env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development'; let devMode = env === 'development'; let outputPath = path.join(__dirname, wpConfig.buildDir); let baseConfig = { entry: wpConfig.entry, output: { path: outputPath, publicPath: `${wpConfig.publicPath}/` }, module: { rules: [ { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/, query: { presets: ['es2015'] } }, { test: /\.yml$/, loader: 'json-loader!yaml-loader' }, { test: /\.html$/, loader: 'html-loader' }, { test: /\.css$/, loader: 'style-loader!css-loader' }, { test: /\.scss$/, loader: 'style-loader!css-loader!sass-loader' }, { test: /\.(svg|png|ttf|woff|woff2)$/, loader: 'file-loader' } ] }, resolve: { modules: [ `${__dirname}/client`, __dirname, 'node_modules' ] }, plugins: [ new webpack.optimize.CommonsChunkPlugin({ names: ['vendor', 'manifest'] }) ], devtool: 'source-map' }; let prodConfig = { output: { filename: '[name].[chunkhash].js', chunkFilename: 'chunk.[id].[chunkhash].js' }, plugins: [ // FIXME: https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/132 new webpack.optimize.UglifyJsPlugin({ minimize: true, compress: {warnings: false} }), new AssetsWebpackPlugin({ path: outputPath }), new webpack.HashedModuleIdsPlugin() ], devtool: 'source-map' }; let devConfig = { output: { filename: '[name].js', chunkFilename: 'chunk.[id].js' }, plugins: [ new webpack.NamedModulesPlugin() ], devtool: 'eval' }; let mrgConfig = devMode ? devConfig : prodConfig; module.exports = merge(baseConfig, mrgConfig);