cannery/assets/webpack.config.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-01-23 00:02:25 -05:00
const path = require('path')
const glob = require('glob')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
2021-03-11 21:12:55 -05:00
module.exports = (env, options) => {
2022-01-23 00:02:25 -05:00
const devMode = options.mode !== 'production'
2021-03-11 21:12:55 -05:00
return {
optimization: {
minimizer: [
new TerserPlugin({ parallel: true, extractComments: true }),
new CssMinimizerPlugin({})
]
},
entry: {
2022-01-23 00:02:25 -05:00
app: glob.sync('./vendor/**/*.js').concat(['./js/app.js'])
2021-03-11 21:12:55 -05:00
},
output: {
2022-01-23 00:02:25 -05:00
filename: '[name].js',
path: path.resolve(__dirname, '../priv/static/js'),
publicPath: '/js/'
2021-03-11 21:12:55 -05:00
},
2022-01-23 00:02:25 -05:00
devtool: devMode ? 'eval-cheap-module-source-map' : undefined,
2021-03-11 21:12:55 -05:00
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
2022-01-23 00:02:25 -05:00
loader: 'babel-loader'
2021-03-11 21:12:55 -05:00
}
},
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
2022-01-23 00:02:25 -05:00
'css-loader',
'postcss-loader',
'sass-loader'
2021-09-02 23:31:15 -04:00
]
},
{
test: /\.(woff(2)?|ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
2022-05-06 23:35:50 -04:00
type: 'asset/resource',
generator: { filename: 'fonts/[name][ext]' }
2021-03-11 21:12:55 -05:00
}
]
},
plugins: [
2022-01-23 00:02:25 -05:00
new MiniCssExtractPlugin({ filename: '../css/app.css' }),
2022-05-06 23:35:50 -04:00
new CopyWebpackPlugin({ patterns: [{ from: 'static/', to: '../' }] })
2021-03-11 21:12:55 -05:00
]
}
2022-01-23 00:02:25 -05:00
}