-
Notifications
You must be signed in to change notification settings - Fork 74
/
webpack.config.production.js
executable file
·190 lines (186 loc) · 4.72 KB
/
webpack.config.production.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* eslint-disable */
const webpack = require("webpack");
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const HappyPack = require("happypack");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const ManifestPlugin = require("webpack-manifest-plugin");
const os = require("os");
const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
const theme = require("./src/theme");
const versionText = require('fs').readFileSync('./version', 'utf8');
const longhornVersion = versionText ? versionText.trim().substring(1).split('-')[0]: '1.7.0';
module.exports = {
devtool: 'source-map',
entry: path.resolve(__dirname, "src", "index.js"),
output: {
filename: "[name].[chunkhash:8].js",
path: path.resolve(__dirname, "dist"),
publicPath: "./",
chunkFilename: "[name].[chunkhash:8].async.js"
},
resolve: {
alias: {
components: path.resolve(__dirname, "src/components/"),
layouts: path.resolve(__dirname, "src/layouts/"),
utils: path.resolve(__dirname, "src/utils/"),
services: path.resolve(__dirname, "src/services/"),
routes: path.resolve(__dirname, "src/routes/"),
models: path.resolve(__dirname, "src/models/")
}
},
module: {
rules: [
{
test: /\.js$/,
include: [path.resolve(__dirname, "src")],
exclude: /node_modules/,
use: ["happypack/loader?id=babel"]
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
importLoaders: 1
}
}
]
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
// sourceMap: true,
importLoaders: 1,
modules: true,
localIdentName: "[name]_[local]-[hash:base64:5]"
}
},
{
loader: "less-loader",
options: {
// sourceMap: true,
javascriptEnabled: true,
modifyVars: theme()
}
}
],
exclude: /node_modules/
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
// sourceMap: true,
importLoaders: 1
}
},
{
loader: "less-loader",
options: {
// sourceMap: true,
javascriptEnabled: true,
modifyVars: theme()
}
}
],
exclude: /src/
},
{
test: /\.(ttf|eot|svg|woff|woff2|png|svg|jpg|gif)$/,
use: [
{
loader: "url-loader",
options: {
limit: 8192
}
}
]
}
]
},
stats: {
children: false
},
performance: {
hints: false
},
externals: {
jquery: "jQuery"
},
node: {
fs: "empty",
module: "empty"
},
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: "styles",
test: /\.(css|less)/,
chunks: "all",
enforce: true
},
commons: {
name: "commons",
chunks: "initial",
minChunks: 2
},
vendors: {
name: "vendors",
test: /[\\/]node_modules[\\/]/,
priority: -10
}
}
},
runtimeChunk: true
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
LH_UI_VERSION: JSON.stringify(longhornVersion),
}
}),
new ProgressBarPlugin(),
new ManifestPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css"
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "src", "index.ejs"),
filename: "index.html",
hash: true
}),
new CleanWebpackPlugin(["dist"]),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, "public")
}
]),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/g,
cssProcessor: require("cssnano"),
cssProcessorOptions: { discardComments: { removeAll: true } },
canPrint: true
}),
new HappyPack({
id: "babel",
loaders: ["babel-loader?cacheDirectory"],
threadPool: happyThreadPool
}),
new webpack.HashedModuleIdsPlugin()
]
};