-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
84 lines (81 loc) · 2.72 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
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { InjectManifest } = require('workbox-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const CopyWebpackPlugin = require("copy-webpack-plugin");
// const ENV = process.env.NODE_ENV || 'development'; // console.log(env);
const ENV = 'production';
const SRC_DIR = 'src/main/resources';
const DST_DIR = 'build/resources/main';
const DST_ASSETS_DIR = path.join(__dirname, DST_DIR, 'assets');
const isProd = (ENV === 'production');
module.exports = {
context: path.resolve(__dirname, SRC_DIR, 'assets'),
entry: {
'js/main': './js/app.js',
'js/push': './js/push.js',
'js/bs': './js/bs.js',
'css/main': './css/app.less',
'css/bs': './css/bs.less',
'css/push': './css/push.less'
},
mode: isProd ? 'production' : 'development',
devtool: isProd ? false : 'source-map',
module: {
rules: [
{
test: /.less$/,
use: [
{loader: MiniCssExtractPlugin.loader, options: {publicPath: '../../'}},
{loader: 'css-loader', options: {sourceMap: !isProd, importLoaders: 1}},
{loader: 'less-loader', options: {sourceMap: !isProd}},
]
},
{
test: /.woff2$/,
type: 'asset/resource',
generator: {
filename: 'fonts/[hash][ext]'
}
}
]
},
output: {
path: DST_ASSETS_DIR,
filename: 'bundles/[name].js',
libraryTarget: 'var',
library: 'Starter'
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: path.join(DST_ASSETS_DIR, 'precache-manifest*.*')
}),
new MiniCssExtractPlugin({
filename: 'bundles/[name].css'
}),
new InjectManifest({
swSrc: path.join(__dirname, SRC_DIR, 'templates/workbox-sw.js'),
swDest: path.join(__dirname, DST_DIR, 'templates/sw.js'),
exclude: [
/\/css\/.*\.js$/,
/\/js\/.*\.css$/,
'fonts/material.icons.woff2'
]
}),
new ESLintPlugin({
extensions: [`js`, `jsx`],
exclude: ['/node_modules/']
}),
new CopyWebpackPlugin({
patterns: [
{from: 'images/**/*', to: '[path]/[name][ext]'},
{from: 'js/material.min.js', to: 'js/'},
]
})
],
resolve: {
extensions: ['.js', '.less', '.css']
},
performance: {hints: false}
};