require('require-yaml'); const webpack = require('webpack'); const path = require('path'); const merge = require('webpack-merge'); const HtmlWebpackPlugin = require('html-webpack-plugin'); let env = process.env.NODE_ENV || 'development'; let mode = env == 'development' ? env : 'production'; let baseConfig = { entry: {salix: 'salix'}, mode: mode, output: { path: path.join(__dirname, 'dist'), publicPath: '/' }, module: { rules: [ { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/, query: { presets: ['@babel/preset-env'], plugins: ['@babel/plugin-syntax-dynamic-import'] } }, { test: /\.yml$/, loader: 'json-loader!yaml-loader' }, { test: /\.html$/, loader: 'html-loader', options: { attrs: [ 'img:src', 'link:href' ] } }, { test: /\.css$/, loader: 'style-loader!css-loader' }, { test: /\.scss$/, use: [ {loader: 'style-loader'}, {loader: 'css-loader'}, { loader: 'sass-loader', options: { includePaths: [ path.resolve(__dirname, 'front/salix/styles') ] } } ] }, { test: /\.(svg|png|ttf|woff|woff2)$/, loader: 'file-loader' }, { test: /manifest\.json$/, type: 'javascript/auto', loader: 'file-loader' } ] }, optimization: { runtimeChunk: true, splitChunks: { chunks: 'all', } }, resolve: { modules: [ `front`, `modules`, `front/node_modules`, `node_modules` ], alias: { 'vn-loopback': `${__dirname}/loopback` } }, watchOptions: { ignored: [ 'node_modules', './modules/*/back/**' ] }, plugins: [ new HtmlWebpackPlugin({ template: 'front/salix/index.ejs', favicon: 'front/salix/favicon.ico', filename: 'index.html', chunks: ['salix'] }) ], devtool: 'source-map', stats: { modules: false, assets: false, children: false, entrypoints: false, colors: true } }; let prodConfig = { output: { filename: '[name].[chunkhash].js', chunkFilename: '[id].[chunkhash].js' }, plugins: [ new webpack.HashedModuleIdsPlugin() ], performance: { maxEntrypointSize: 2000000, maxAssetSize: 2000000 } }; let devConfig = { output: { filename: '[name].js', chunkFilename: '[id].js' }, plugins: [ new webpack.HotModuleReplacementPlugin() ], devServer: { host: '0.0.0.0', port: 5000, publicPath: '/', contentBase: 'dist', quiet: false, noInfo: false, hot: true, inline: true, stats: baseConfig.stats, proxy: { '/api': 'http://localhost:3000', '/*/api/**': { target: 'http://localhost:3000', pathRewrite: {'^/[\\w-]+': ''} } } } }; let mrgConfig = mode === 'development' ? devConfig : prodConfig; module.exports = merge(baseConfig, mrgConfig);