-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
173 lines (155 loc) · 4.2 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
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
const webpack = require('webpack')
const path = require('path')
const { VueLoaderPlugin } = require('vue-loader')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CopyPlugin = require('copy-webpack-plugin')
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const sass = require('sass')
module.exports = env => {
const isProduction = env && env.production
function commonPlugins() {
return [
new VueLoaderPlugin(),
new webpack.EnvironmentPlugin({
NODE_ENV: isProduction ? 'production' : 'development'
}),
new MiniCssExtractPlugin({
filename: 'assets/css/[name].css'
})
]
}
function devPlugins() {
return commonPlugins().concat([
new webpack.HotModuleReplacementPlugin()
])
}
function productionPlugins() {
return [
new CopyPlugin({
patterns: [
{
from: 'public/**/*',
to: '[name][ext]'
},
]
})
].concat(commonPlugins()).concat([
// new BundleAnalyzerPlugin()
])
}
return {
target: 'web',
mode: isProduction ? 'production' : 'development',
entry: {
index: './src/main.ts',
},
resolve: {
extensions: ['.ts', '.js', '.vue', '.scss'],
alias: {
// Use runtime-only vue to reduce bundle size https://medium.com/@joanxie/utilize-webpacks-tree-shaking-in-your-vue-application-a0dc63c0dfac
'vue$': 'vue/dist/vue.runtime.esm.js'
},
},
output: {
filename: 'assets/js/[name].js',
path: path.resolve(__dirname, './dist/'),
publicPath: '/'
},
module: {
rules: [
{ // TypeScript loader!
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
// exclude: /node_modules/,
options: {
transpileOnly: true,
appendTsSuffixTo: [/\.vue$/],
}
}
]
},
{ // Vue loader must come after TS loader, or we get strange bug
// where dev server can't find vue components on reload.
test: /\.vue$/,
loader: 'vue-loader'
},
{ // Process imported stylesheets as well as Vue style segments.
test: /\.s?css$/,
use: [
isProduction ? MiniCssExtractPlugin.loader : 'vue-style-loader',
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
// Prefer `dart-sass` cos node-sass seems troublesome
implementation: sass,
sourceMap: true
}
}
]
},
{ // Custom handle the indented SASS syntax.
test: /\.sass$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
implementation: sass,
sourceMap: true,
sassOptions: {
indentedSyntax: true
}
}
}
]
},
{
// Images
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
type: 'asset'
},
{
test: /\.tsv$/,
loader: 'csv-loader',
options: {
skipEmptyLines: true,
delimiter: "\t"
}
}
]
},
plugins: isProduction ? productionPlugins() : devPlugins(),
// Sourcemap settings recommended by ts-loader documentation
devtool: isProduction ? 'source-map' : 'eval-cheap-module-source-map',
devServer: isProduction ? undefined : {
host: 'localhost',
hot: true,
port: 8080,
contentBase: path.resolve(__dirname, './public/'),
watchContentBase: true,
watchOptions: {
ignored: /node_modules/,
poll: true,
},
historyApiFallback: {
rewrites: [
{ from: /./, to: '/index.html' }
]
}
}
}
}