-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
executable file
·135 lines (133 loc) · 3.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
const path = require('path');
const os = require('os');
const HappyPack = require('happypack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const rp = file => path.resolve(__dirname, file);
const plugins = [
new HappyPack({
id: 'ts',
threads: os.cpus().length,
use: [
{
path: 'ts-loader',
query: {
happyPackMode: true,
configFile: rp('./tsconfig.json'),
},
},
],
}),
new ForkTsCheckerWebpackPlugin({
tsconfig: rp('tsconfig.json'),
}),
new MiniCssExtractPlugin({
filename: `ugli/[name].css`,
chunkFilename: '[id].css',
}),
];
module.exports = {
mode: 'production',
entry: {
react: './src/components/react/index.ts',
},
output: {
path: path.resolve(__dirname, 'build'),
filename: 'ugli.[name].js',
},
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: false, // set to true if you want JS source maps
}),
new OptimizeCSSAssetsPlugin({}),
],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: ['happypack/loader?id=ts'],
include: [rp('src')],
exclude: ['/**/__test__/*', 'node_modules'],
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
autoprefixer: false,
minimize: true,
},
},
{
loader: 'postcss-loader',
options: {
plugins: function() {
return [
require('autoprefixer')({
browsers: ['iOS >= 7', 'android >= 4', 'ie >= 9'],
}),
];
},
},
},
{
loader: 'less-loader',
},
],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /font\.(svg|ttf|woff|eot)|\.otf/i,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
name: `ugli/iconfont/[name]${hash}.[ext]`,
},
},
],
},
{
test: /\.(jpe?g|gif|png|svg)$/i,
use: [
{
loader: 'image-webpack-loader',
options: {
byPassOnDebug: true,
mozjpeg: { progressive: true },
optipng: { optimizationLevel: 3 },
pngquant: { quality: '65-80' },
},
},
{
loader: 'url-loader',
options: {
limit: 10000,
name: `ugli/img/[name]${hash}.[ext]`,
},
},
],
},
],
},
plugins: plugins,
resolve: {
extensions: ['.js', '.ts', '.tsx', '.json'],
alias: {
utils: path.resolve(__dirname, 'src/utils'),
style: path.resolve(__dirname, 'src/style'),
},
},
};