var path = require('path'); var webpack = require('webpack'); var AssetsWebpackPlugin = require('assets-webpack-plugin'); var merge = require('webpack-merge'); var wpConfig = require('./webpack.config.json'); let env = process.env.NODE_ENV || 'development'; var devMode = env === 'development'; var outputPath = path.join(__dirname, wpConfig.buildDir); var publicPath = wpConfig.buildDir +'/'; var baseConfig = { entry: wpConfig.entry, mode: devMode ? 'development' : 'production', output: { path: outputPath, publicPath: publicPath }, module: { rules: [ { test: /\.css$/, loader: 'style-loader!css-loader' }, { test: /\.yml$/, loader: 'json-loader!yaml-loader' }, { test: /\.xml$/, loader: 'raw-loader' }, { test: /\.ttf$/, loader: 'file-loader' } ] }, resolve: { modules: [ __dirname +'/js', __dirname, 'node_modules', '/usr/lib/node_modules' ] }, node: { __dirname: true }, plugins: [ new AssetsWebpackPlugin({ path: outputPath }), new webpack.DefinePlugin({ _DEV_MODE: devMode, _DEV_SERVER_PORT: wpConfig.devServerPort, _PUBLIC_PATH: JSON.stringify (publicPath) }) ], optimization: { runtimeChunk: true, splitChunks: { chunks: 'all', } }, watchOptions: { ignored: /node_modules/ } }; var prodConfig = { output: { filename: '[name].[chunkhash].js', chunkFilename: 'chunk.[id].[chunkhash].js' }, plugins: [ new webpack.HashedModuleIdsPlugin() ], devtool: 'source-map' }; var devConfig = { output: { filename: '[name].js', chunkFilename: 'chunk.[id].js' }, plugins: [ new webpack.NamedModulesPlugin() ], devServer: { host: '0.0.0.0', port: wpConfig.devServerPort, headers: { 'Access-Control-Allow-Origin': '*' }, stats: { chunks: false } }, devtool: 'eval' }; var mrgConfig = devMode ? devConfig : prodConfig; module.exports = merge(baseConfig, mrgConfig);