const { resolve } = require('path') const webpack = require('webpack') // const UglifyJsPlugin = require('uglifyjs-webpack-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin') // const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin') // const CompressionPlugin = require('compression-webpack-plugin') const ManifestPlugin = require('webpack-manifest-plugin') const CleanWebpackPlugin = require('clean-webpack-plugin') const nodeExternals = require('webpack-node-externals') const browserConfig = { mode: 'production', entry: { bundle: [ './src/app-client.js' ] }, output: { path: resolve(__dirname, 'public/static'), filename: '[name].js', // filename: '[name].[contenthash].js', publicPath: '/static/' }, // devtool: 'eval-source-map', module: { rules: [ { test: /\.js$/, use: [ 'babel-loader' ], exclude: '/node_modules/' }, { test: /\.scss$/, use: [ MiniCssExtractPlugin.loader, { loader: 'css-loader', options: { modules: true, importLoaders: 2, localIdentName: '[name]__[local]___[hash:base64:5]' } }, { loader: 'postcss-loader' }, { loader: 'sass-loader' } ] }, { test: /\.(png|jpg)$/, exclude: /node_modules/, loader: 'url-loader', options: { limit: 8192 } } ] }, plugins: [ new webpack.DefinePlugin({ __isBrowser__: 'true' }), new CleanWebpackPlugin(['public/static', 'build'], {}), new MiniCssExtractPlugin(), // new CompressionPlugin({}), new ManifestPlugin() ], node: { fs: 'empty' } } const serverConfig = { entry: './src/server.js', target: 'node', externals: [nodeExternals()], output: { path: resolve(__dirname, 'build'), filename: 'server.js', publicPath: '/' }, module: { rules: [ { test: /\.js$/, use: [ 'babel-loader' ], exclude: '/node_modules/' }, { test: /\.scss$/, use: [ MiniCssExtractPlugin.loader, { loader: 'css-loader', options: { modules: true, exportOnlyLocals: true, importLoaders: 2, localIdentName: '[name]__[local]___[hash:base64:5]' } }, { loader: 'postcss-loader' }, { loader: 'sass-loader' } ] }, { test: /\.(png|jpg)$/, exclude: /node_modules/, loader: 'url-loader', options: { limit: 10000 } } ] }, plugins: [ new webpack.DefinePlugin({ __isBrowser__: 'false' }), new MiniCssExtractPlugin() ] } module.exports = [browserConfig, serverConfig]