-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwebpack.config.js
118 lines (113 loc) · 2.8 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const { VueLoaderPlugin } = require('vue-loader');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const env = process.env.NODE_ENV;
const sourceMap = env === 'development';
const minify = env === 'production';
const config = {
entry: path.join(__dirname, 'src', 'main.js'),
mode: env,
output: {
publicPath: '',
},
serve: {
host: 'localhost',
port: 3000,
},
optimization: {
splitChunks: {
chunks: 'all',
},
},
devtool: sourceMap ? 'cheap-module-eval-source-map' : undefined,
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [path.join(__dirname, 'src')],
},
{
test: /\.scss$/,
loader: 'vue-style-loader!css-loader!resolve-url-loader!sass-loader',
},
{
test: /\.(png|jp(e*)g|svg|ico)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 1,
name: 'images/[hash]-[name].[ext]',
},
},
],
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
},
},
],
},
],
},
plugins: [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
filename: path.join(__dirname, 'dist', 'index.html'),
template: path.join(__dirname, 'static', 'index.html'),
inject: true,
minify: minify
? {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
}
: false,
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.join(__dirname, 'static', 'assets', '*'),
to: path.join(__dirname, 'dist', 'assets'),
flatten: true,
},
],
options: {
concurrency: 100,
},
}),
],
resolve: {
alias: {
'@API$': path.resolve(__dirname, 'src/helpers/API.js'),
'@Config$': path.resolve(__dirname, 'src/config.js'),
'@Component': path.resolve(__dirname, 'src/components/'),
'@View': path.resolve(__dirname, 'src/views/'),
'@MasterStyle$': path.resolve(__dirname, 'src/scss/master.scss'),
'@Asset': path.resolve(__dirname, 'src/assets/'),
'@Test': path.resolve(__dirname, '__test__'),
'@': path.resolve(__dirname, 'src/'),
},
},
};
if (minify) {
config.optimization.minimizer = [
new UglifyJsPlugin({
cache: true,
parallel: true,
}),
];
}
module.exports = config;