-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.base.js
124 lines (120 loc) · 3.22 KB
/
webpack.config.base.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
'use strict';
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const ctxDir = path.resolve(__dirname);
const srcDir = path.resolve(ctxDir, 'src');
const loadersDir = path.resolve(ctxDir, 'loaders');
const publicDir = path.resolve(ctxDir, 'public');
const vendorDir = path.resolve(ctxDir, 'vendor');
const outDir = path.resolve(ctxDir, 'dist');
const publicPath = '/';
module.exports = {
mode: 'development',
devtool: 'cheap-module-source-map',
context: ctxDir,
entry: {
main: ['normalize.css', srcDir],
lib: [
'react', 'react-dom',
'react-router', 'react-router-dom'
]
},
output: {
clean: true,
path: outDir,
publicPath,
filename: '[name].[chunkhash].js'
},
resolve: {
alias: {
'src': srcDir,
'public': publicDir,
'vendor': vendorDir
}
},
resolveLoader: {
alias: {
'>': loadersDir
}
},
module: {
rules: [{
include: [publicDir],
use: [{
loader: '>/public-loader',
options: {
publicPath,
publicDir
}
}]
}, {
test: /\.css$/,
include: [/node_modules/, vendorDir],
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader'
]
}, {
test: /\.less$/,
include: [srcDir],
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[local]-[hash:base64:5]'
}
}
},
'postcss-loader',
'less-loader'
]
}, {
test: /\.less$/,
include: [vendorDir],
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'less-loader'
]
}, {
test: /\.js$/,
include: [
srcDir,
// https://github.com/webpack/loader-utils/issues/92
/node_modules\/loader-utils/
],
use: [{
loader: 'babel-loader'
}]
}, {
test: /\.md$/,
use: [{
loader: '>/markdown-react-loader'
}]
}, {
test: /\.(eot|woff|ttf|svg|jpg|png|ico)$/,
exclude: [publicDir],
type: 'asset'
}]
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css'
}),
new HtmlWebpackPlugin({
template: 'src/index.html'
}),
// SPA 404 redirect.
new HtmlWebpackPlugin({
template: 'src/index.html',
filename: '404.html'
}),
new ESLintPlugin()
]
};