2021-01-08 03:55:45 +08:00
|
|
|
const path = require('path');
|
|
|
|
const glob = require('glob');
|
|
|
|
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
2021-01-21 20:11:45 +08:00
|
|
|
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
|
2021-01-08 03:55:45 +08:00
|
|
|
|
2021-03-17 18:17:52 +08:00
|
|
|
// Make sure NODE_ENV is set, so that @tailwindcss/jit is in watch mode in development.
|
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
|
2021-01-08 03:55:45 +08:00
|
|
|
module.exports = (env, options) => {
|
|
|
|
const devMode = options.mode !== 'production';
|
|
|
|
|
|
|
|
return {
|
|
|
|
optimization: {
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin({ cache: true, parallel: true, sourceMap: devMode }),
|
|
|
|
new OptimizeCSSAssetsPlugin({})
|
|
|
|
]
|
|
|
|
},
|
|
|
|
entry: {
|
|
|
|
'app': glob.sync('./vendor/**/*.js').concat(['./js/app.js'])
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name].js',
|
2021-03-17 08:53:44 +08:00
|
|
|
path: path.resolve(__dirname, (devMode ? '../priv/static_dev/js' : '../priv/static/js')),
|
2021-01-08 03:55:45 +08:00
|
|
|
publicPath: '/js/'
|
|
|
|
},
|
|
|
|
devtool: devMode ? 'eval-cheap-module-source-map' : undefined,
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.[s]?css$/,
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
'css-loader',
|
2021-01-08 05:13:17 +08:00
|
|
|
'postcss-loader',
|
2021-01-08 03:55:45 +08:00
|
|
|
],
|
2021-01-21 20:11:45 +08:00
|
|
|
},
|
|
|
|
{
|
2021-03-12 18:57:01 +08:00
|
|
|
test: /\.(ttf|woff|woff2|eot|svg)$/,
|
2021-01-21 20:11:45 +08:00
|
|
|
use: ['file-loader'],
|
|
|
|
},
|
2021-01-08 03:55:45 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new MiniCssExtractPlugin({ filename: '../css/app.css' }),
|
2021-01-21 20:11:45 +08:00
|
|
|
new MonacoWebpackPlugin({
|
|
|
|
languages: ['markdown']
|
|
|
|
})
|
2021-01-08 03:55:45 +08:00
|
|
|
]
|
|
|
|
.concat(devMode ? [new HardSourceWebpackPlugin()] : [])
|
|
|
|
}
|
|
|
|
};
|