forked from chipuni/engelsystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
104 lines (96 loc) · 2.64 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
const nodeEnv = (process.env.NODE_ENV || 'development').trim();
// eslint-disable-next-line
const __DEV__ = nodeEnv !== 'production';
const devtool = __DEV__ ? 'source-map' : undefined;
const plugins = [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(nodeEnv),
},
}),
new MiniCssExtractPlugin({
filename: '[name]-[contenthash].css',
chunkFilename: '[id]-[contenthash].css',
}),
new WebpackManifestPlugin({}),
];
let themeFileNameRegex = /theme\d+/;
if (process.env.THEMES) {
const themes = process.env.THEMES.replace(/,/g, '|');
themeFileNameRegex = new RegExp(`theme(${themes})\\.`);
}
const themePath = path.resolve('resources/assets/themes');
const themeEntries = fs
.readdirSync(themePath)
.filter((fileName) => fileName.match(themeFileNameRegex))
.reduce((entries, themeFileName) => {
entries[path.parse(themeFileName).name] = `${themePath}/${themeFileName}`;
return entries;
}, {});
module.exports = {
mode: __DEV__ ? 'development' : 'production',
context: __dirname,
resolve: {
extensions: ['.js'],
},
entry: {
...themeEntries,
vendor: './resources/assets/js/vendor.js',
},
output: {
path: path.resolve('public/assets'),
filename: '[name]-[contenthash].js',
publicPath: '',
clean: true,
},
optimization: {
minimizer: __DEV__ ? [] : [new CssMinimizerPlugin(), new TerserPlugin()],
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
},
{ test: /\.(jpg|eot|ttf|otf|svg|woff2?)(\?.*)?$/, type: 'asset/resource' },
{ test: /\.json$/, loader: 'json-loader' },
{
test: /\.(scss|css)$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{ loader: 'css-loader' },
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [['autoprefixer']],
},
},
},
{
loader: 'resolve-url-loader',
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
sassOptions: {
quietDeps: true,
},
},
},
],
},
],
},
plugins,
devtool,
};