This repository was archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
133 lines (116 loc) · 2.49 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
const path = require('path')
const Webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const devServerPort = 9000
const dest = path.resolve(__dirname, './docs/')
const html = new HtmlWebpackPlugin({
template: path.resolve(__dirname, './src/index.html'),
filename: 'index.html',
inject: 'body'
})
const provideRiot = new Webpack.ProvidePlugin({
riot: 'riot'
})
const riotRule = {
test: /\.tag$/,
enforce: 'pre',
exclude: /node_modules/,
use: 'riotjs-loader'
}
const jsRule = {
test: /\.js$|\.tag$/,
exclude: /node_modules/,
use: 'babel-loader'
}
const devRules = [
riotRule,
jsRule,
{
test: /\.(html)$/,
use: {
loader: 'html-loader',
options: {
attrs: ['img:src', 'img:data-src', 'img:srcset', 'source:srcset'],
minimize: false,
root: '.'
}
}
},
{
test: /\.(jpe?g|png|gif)$/i,
use: ['url-loader']
},
{
test: /\.scss$/i,
use: ['style-loader', 'css-loader', 'sass-loader']
}
]
const prodRules = [
riotRule,
jsRule,
{
test: /\.(html)$/,
use: {
loader: 'html-loader',
options: {
attrs: ['img:src', 'img:data-src', 'img:srcset', 'source:srcset'],
minimize: true
}
}
},
{
test: /\.(jpe?g|png|gif)$/i,
use: ['url-loader']
// use: ['file-loader']
},
{
test: /\.scss$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader'
]
}
]
const config = {
module: {},
resolve: {
modules: ['node_modules']
},
entry: {
main: path.resolve(__dirname, './src/index.js')
},
output: {
// filename: 'bundle-[hash].js',
filename: 'bundle.js',
publicPath: `http://localhost:${devServerPort}/`,
path: dest
},
plugins: [html, provideRiot]
}
module.exports = (env, argv) => {
if (argv.mode === 'development') {
config.devtool = '#cheap-source-map'
config.plugins.push(new Webpack.HotModuleReplacementPlugin())
config.module.rules = devRules
config.devServer = {
hot: true,
inline: true,
contentBase: dest,
publicPath: `http://localhost:${devServerPort}/`,
port: devServerPort
}
} else {
config.module.rules = prodRules
config.output.publicPath = './'
config.plugins.push(
new MiniCssExtractPlugin({
// filename: 'bundle-[hash].css'
filename: 'bundle.css'
})
)
}
return config
}