-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
191 lines (175 loc) · 4.69 KB
/
webpack.config.js
File metadata and controls
191 lines (175 loc) · 4.69 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const Autoprefixer = require('autoprefixer');
const PostCssModules = require("postcss-modules");
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CssMinimizerWebpackPlugin = require("css-minimizer-webpack-plugin");
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const SUPPORTED_LANGS = /cs/;
module.exports = (env) => {
const isProduction = false;//process.env.NODE_ENV;
const module = 'admin';
const entryPoints = {
admin: './assets/js/app.js',
};
const config = {
entry: {
[module]: entryPoints[module] // Dynamicky přidáme pouze vybraný entry point
},
output: {
path: path.resolve(__dirname, 'dist', module), // každý modul bude mít svůj adresář
publicPath: `/dist/${module}/`,
filename: 'js/[name].js',
chunkFilename: 'js/[name].[fullhash:5].js'
},
// Development or production?
mode: process.env.NODE_ENV,
// Source map generation
devtool: isProduction ? false : 'eval-cheap-module-source-map',
module: {
rules: [
{
// Exposes jQuery for use outside Webpack build
test: require.resolve('jquery'),
loader: 'expose-loader',
options: {
exposes: ['jQuery', '$', 'jquery']
}
},
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-proposal-class-properties']
}
}
},
{
test: /\.tsx?$/,
use: 'raw-loader',
},
{
test: /\.module.scss$/,
use: [{
loader: MiniCssExtractPlugin.loader,
}, {
loader: 'css-loader', // translates CSS into CommonJS modules
options: {
sourceMap: !isProduction,
modules: {
localIdentName: isProduction ? '[hash:base64]' : '[path][local]__[hash:base64:5]',
},
}
}, {
loader: 'postcss-loader', // Run post css actions
options: {
sourceMap: !isProduction,
plugins: function () { // post css plugins, can be exported to postcss.config.js
return [
PostCssModules({
generateScopedName: isProduction ? '[hash:base64]' : '[path][local]__[hash:base64:5]',
}),
Autoprefixer,
];
}
}
}, {
loader: 'sass-loader', // compiles Sass to CSS
options: {
sourceMap: !isProduction,
}
}]
},
{
test: /\.(scss)$/,
exclude: /\.module.scss$/,
use: [{
loader: MiniCssExtractPlugin.loader,
}, {
loader: 'css-loader', // translates CSS into CommonJS modules
options: {
sourceMap: !isProduction,
}
}, {
loader: 'postcss-loader', // Run post css actions
options: {
sourceMap: !isProduction,
postcssOptions: {
plugins: function () { // post css plugins, can be exported to postcss.config.js
return [
// require('precss'),
Autoprefixer,
];
}
}
}
}, {
loader: 'sass-loader', // compiles Sass to CSS
options: {
sourceMap: !isProduction,
}
}]
},
{
test: /\.(css)$/,
use: [
'style-loader',
'css-loader',
]
},
{
test: /\.(ttf|woff|woff2|eot|svg)$/i,
type: 'asset/resource',
generator: {
filename: 'fonts/[hash][ext][query]'
}
},
]
},
plugins: [
// remove old dist files
new CleanWebpackPlugin(),
// Provides jQuery for other JS bundled with Webpack
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
Popper: ["popper.js", "default"],
}),
// some plugins with webpack include all locales which then is huge in size -> include only defined
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, SUPPORTED_LANGS),
new webpack.ContextReplacementPlugin(/flatpickr[\/\\]dist[\/\\]l10n$/, SUPPORTED_LANGS),
// extract css sheets to a separate file so we can include it directly in layout latte
new MiniCssExtractPlugin({
filename: 'css/[name].css',
chunkFilename: 'css/[name].[hash:5].css',
}),
],
resolve: {
modules: ['node_modules'],
alias: {
JsComponents: path.resolve(__dirname, 'src'),
'adt-fancyadmin': path.resolve(__dirname),
'~/src': path.resolve(__dirname, 'src')
}
}
};
if (isProduction) {
config.plugins.push(
// Generate statistics
new BundleAnalyzerPlugin({
analyzerMode: 'disabled',
generateStatsFile: true,
statsOptions: { source: false }
}),
);
config.plugins.push(
// Minify CSS
new CssMinimizerWebpackPlugin()
)
}
return config;
};