This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
107 lines (102 loc) · 2.52 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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const webpack = require('webpack');
const ExtractTextSass = new ExtractTextPlugin("index.one.[contenthash].css");
const ExtractTextLess = new ExtractTextPlugin("index.two.[contenthash].css");
const getConfig = (env) => {
let config = {
entry: {
app: './src/entry',
},
output: {
filename: '[name].[chunkhash].js',
path: __dirname + '/dist',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.scss'],
},
plugins: [
new HtmlWebpackPlugin({
title: 'React-Redux-Weback-Typescript-AntDesign',
template: 'src/index.ejs'
}),
ExtractTextSass,
ExtractTextLess,
],
module: {
rules: [
{
test: /\.(jsx|js)$/,
use: [{ loader: 'babel-loader' }],
},
{
test: /\.(ts|tsx)$/,
use: [
{loader: 'babel-loader'},
{loader: 'ts-loader'},
],
},
{
test: /\.(css|scss)$/,
loader: ExtractTextSass.extract({
use: ['css-loader', 'sass-loader'],
fallback:'style-loader',
})
},
{
test: /\.(less)$/,
loader: ExtractTextLess.extract({
use: ['css-loader', 'less-loader'],
fallback:'style-loader',
})
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file-loader?name=fonts/[name].[hash].[ext]'
}
],
},
};
if (env === 'dev') {
config.devServer = {
proxy: {
'/api': {
target: {
host: 'localhost',
protocol: 'http',
port: 3000,
},
changeOrigin: true,
secure: false,
},
},
};
config.devtool = 'source-map';
}
if (env === 'prod') {
config.plugins.push(
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.[chunkhash].js',
minChunks: function (module) {
return module.context && module.context.indexOf('node_modules') !== -1;
}
})
);
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true
},
compress: {
screw_ie8: true
},
comments: false
})
)
}
return config;
};
module.exports = getConfig;