-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
76 lines (65 loc) · 2.11 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
import Path from '@mojojs/path';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import OptimizeCSSAssetsPlugin from 'css-minimizer-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import {VueLoaderPlugin} from 'vue-loader';
import webpack from 'webpack';
const assetsDir = process.env.WEBPACK_ASSETS_DIR || Path.currentFile().sibling('assets').toString();
const isDev = process.env.NODE_ENV !== 'production';
const output = {
filename: isDev ? '[name].development.js' : '[name].[chunkhash].js',
path: process.env.WEBPACK_OUT_DIR || Path.currentFile().sibling('public', 'asset').toString(),
publicPath: ''
};
const entry = new Path(assetsDir, 'main.js').toString();
const minimizer = [];
if (!isDev) {
minimizer.push(new TerserPlugin({parallel: true}));
minimizer.push(new OptimizeCSSAssetsPlugin({}));
}
const rules = [];
rules.push({
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
plugins: ['@babel/plugin-transform-runtime'],
presets: ['@babel/preset-env']
}
}
});
rules.push({
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, {loader: 'css-loader', options: {sourceMap: true, url: false}}]
});
rules.push({test: /\.vue$/, use: 'vue-loader'});
rules.push({
test: /\.s(a|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
{loader: 'css-loader', options: {sourceMap: true, url: false}},
{loader: 'sass-loader', options: {sourceMap: true}}
]
});
const config = {
entry: {cavil: entry},
mode: isDev ? 'development' : 'production',
module: {rules},
optimization: {minimizer},
output,
plugins: [
new CopyWebpackPlugin({
patterns: [{from: './node_modules/@fortawesome/fontawesome-free/webfonts', to: './webfonts'}]
}),
new MiniCssExtractPlugin({filename: isDev ? '[name].development.css' : '[name].[contenthash].css'}),
new VueLoaderPlugin(),
new webpack.DefinePlugin({
__VUE_OPTIONS_API__: 'true',
__VUE_PROD_DEVTOOLS__: 'false',
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false'
})
]
};
export default config;