-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
148 lines (139 loc) · 3.67 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
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
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const path = require('path');
module.exports = (env, argv) => {
env = env || {}
const currentMode = argv.mode !== undefined ? argv.mode : 'development';
return [
{
mode: currentMode,
entry: './resources/js/main.js',
devServer: {
inline: true,
hot: true,
hotOnly: true,
headers: {
"Access-Control-Allow-Origin": "*"
},
port: 8080
},
output: {
// maybe there's a better way to define this but I didn't experiment
path: __dirname,
filename: 'build/js/build.js', // this is what is printed in the log, so whole path here
publicPath: env.server ? 'http://localhost:8080/' : ''
},
stats: {
children: false,
hash: false,
modules: false,
},
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
cache: true,
})
]
},
module: {
rules: [
{
test: /\.vue$/,
use: {
loader: 'vue-loader',
options: {
prettify: false,
postcss: {
useConfigFile: false,
plugins: [
require('postcss-preset-env')({ stage: 0 }),
]
}
}
}
},
{
// This is for the javascript directly in main.js (i.e. not from a .vue component)
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/env', { modules: false }],
],
plugins: [
'@babel/plugin-transform-runtime',
]
}
},
include: [
path.resolve(__dirname, 'resources'),
],
},
{
// for images used in .vue components
test: /\.(jpg|png|gif|svg)/,
use: {
loader: 'file-loader',
options: {
name: 'images/[hash].[ext]', // this is what will be appended to __webpack_public_path__ set in main.js
outputPath: 'build/',
publicPath: env.server ? 'http://localhost:8080/build/' : './',
esModule: false, // https://github.com/webpack/webpack/issues/4742
}
}
},
{
test: /\.css$/,
use: [
'vue-style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 2,
}
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
// Note that contrary to postcss-loader documentation, this has to be an array, not a function,
// otherwise the browserslist cache has no effect, which leads to bad performance:
plugins: [
require('postcss-preset-env')({ stage: 0 }),
]
}
}
],
}
]
},
resolve: {
alias: {
// This is the default (package.module)
// vue$: 'vue/dist/vue.runtime.esm.js'
}
},
// Plugins are loaded with "new" because we need an instance to hold the configuration
plugins: [
// always:
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: 'build/css/[name].css',
}),
].concat(currentMode === 'production' ? [
// only on live build:
// This provides a .gz file for serving with "gzip_static on;"
new CompressionPlugin({}),
] : []).concat(env.server ? [
// only when dev-server is enabled:
new webpack.HotModuleReplacementPlugin()
] : []),
devtool: currentMode === 'production' ? false : 'cheap-module-source-map' // the only one that works: https://github.com/webpack/webpack/issues/2145#issuecomment-294361203
}
];
};