forked from alwaysmavs/netless-test-whiteboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
152 lines (137 loc) · 3.88 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
/**
* Created by taozeyu on 2017/6/4.
*/
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const basic = {
entry: [
"./src/index.ts",
],
output: {
filename: "javascript/index-[hash].js",
path: __dirname + "/build",
publicPath: "/",
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".svg"],
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
enforce: "pre",
loader: "source-map-loader",
exclude: [
path.resolve(__dirname, "../submodules/white-framework/node_modules")
]
}, {
test: /\.tsx?$/,
use: [
'ts-loader',
{
loader: 'ui-component-loader',
options: {
'lib': 'antd',
'libDir': 'es',
'style': false,
}
},
],
exclude: /node_modules/,
}, {
test: /\.less$/,
use: [
{loader: "style-loader"}, {loader: "css-loader"}, {loader: "less-loader"}
]
}, {
test: /\.css$/,
use: [
{loader: "style-loader"}, {loader: "css-loader"}
]
}, {
test: /\.svg$/,
exclude: /node_modules/,
loader: 'svg-react-loader',
query: {
classIdPrefix: '[name]-[hash:8]__',
propsMap: {
fillRule: 'fill-rule',
foo: 'bar'
},
xmlnsTest: /^xmlns.*$/
}
}, {
test: /\.(png|jpg)$/,
loader: 'url-loader?limit=8192&name=icons/[hash:8].[name].[ext]'
}]
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index-template.html",
filename: "index.html",
path: __dirname + "/build",
inject: "body",
}),
new ForkTsCheckerWebpackPlugin({ memoryLimit : 10000, workers: 2 })
]
};
const development = {
devServer: {
port: 3000,
historyApiFallback: true,
// proxy: {
// "/api": {
// pathRewrite: {'^/api': '/'},
// target: "http://bad006a941144606a2cf5b693c5dddea-cn-hangzhou.alicloudapi.com/",
// changeOrigin: true
// },
// },
},
};
const production = {
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
],
};
function merge(conf1, conf2) {
if (conf1 instanceof Array && conf2 instanceof Array) {
const array = [];
conf1.forEach(function (e) {
array.push(e);
});
conf2.forEach(function (e) {
array.push(e);
});
return array;
}
const result = {};
function mergeValue(v1, v2) {
if (typeof v1 === "object" && typeof v2 === "object") {
return merge(v1, v2);
} else if (v1 === undefined) {
return v2;
} else {
return v1;
}
}
for (const key in conf1) {
result[key] = mergeValue(conf1[key], conf2[key]);
}
for (const key in conf2) {
if (!(key in conf1)) {
result[key] = mergeValue(conf1[key], conf2[key]);
}
}
return result;
}
module.exports = merge(
basic,
process.env.NODE_ENV === 'production' ? production : development
);