-
Notifications
You must be signed in to change notification settings - Fork 32
/
webpack.config.js
169 lines (155 loc) · 3.84 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
require('dotenv').config();
const path = require('path');
const fs = require('fs');
const lessToJs = require('less-vars-to-js');
const HTMLPlugin = require('html-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const themeVariables = lessToJs(fs.readFileSync(path.join(__dirname, './src/styles/ant-vars.less'), 'utf8'));
const { ProvidePlugin } = require('webpack');
const devMode = process.env.NODE_ENV !== 'production';
const plugins = [
new CleanWebpackPlugin(['build']),
new ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
jquery: 'jquery',
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: devMode ? '[name].css' : '[name].[hash].css',
chunkFilename: devMode ? '[id].css' : '[id].[hash].css',
}),
new HTMLPlugin({
chunks: ['main'],
filename: "index.html",
template: `${__dirname}/src/index.html`,
}),
new HTMLPlugin({
chunks: ['embedmap'],
filename: "mapEmbed.html",
template: `${__dirname}/src/mapEmbed.html`,
}),
// new ExtractPlugin('bundle.[hash].css'),
new CopyWebpackPlugin([
{
from: 'src/Images/**/*',
transformPath(targetPath) {
return targetPath.split('src/')[1];
}
},
{
flatten: true,
from: 'src/vendor/scripts/*',
to: 'vendor/scripts',
},
]),
];
module.exports = {
resolve: {
alias: {
'masonry': 'masonry-layout',
'isotope': 'isotope-layout'
},
extensions: ['.js', '.json', '.jsx'],
},
mode: 'development',
optimization: {
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})],
},
plugins,
entry: {
main: `${__dirname}/src/main.js`,
embedmap: `${__dirname}/src/embedmap-main.js`
},
devtool: 'source-map',
// Stick it into the "path" folder with that file name
output: {
filename: '[name].[hash].js',
path: `${__dirname}/build`,
},
module: {
rules: [
// If it's a .js file not in node_modules, use the babel-loader
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
plugins: [
['import', {
libraryName: 'antd',
style: true
}],
],
},
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
],
},
// If it's a less file
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
},
{
loader: 'less-loader',
options: {
javascriptEnabled: true,
modifyVars: themeVariables,
},
},
],
},
{
test: /\.(woff|woff2|ttf|eot|glyph)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
name: 'font/[name].[ext]',
},
},
],
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'babel-loader',
},
{
loader: '@svgr/webpack',
options: {
babel: false,
icon: true,
},
},
],
},
{
test: /\.(png|jpg|gif)$/,
use: [
'file-loader'
]
}
],
},
devServer: {
historyApiFallback: true,
},
resolve: {
extensions: [".js", ".jsx", ".json"],
},
};