-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
143 lines (141 loc) · 3.55 KB
/
webpack.config.js
File metadata and controls
143 lines (141 loc) · 3.55 KB
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
const Path = require('path');
const webpack = require("webpack");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const Mocker = require('webpack-api-mocker');
const outPath = Path.join(__dirname, './dist');
const sourcePath = Path.join(__dirname, './src');
module.exports = (env, options) => {
const config = {
context: sourcePath,
entry: {
// vendor: ['classnames', 'react', 'react-dom', '@reach/router', 'react-modal', 'rc-cascader'],
// bootstrap: './framework/vendors/bootstrap/bootstrap.scss',
main: './index.tsx',
polyfills: './polyfills.ts'
},
output: {
path: outPath,
// publicPath: '/',
filename: "[name].js"
},
// optimization: {
// splitChunks: {
// cacheGroups: {
// commons: {
// test: /[\\/]node_modules[\\/]/,
// name: 'vendors',
// chunks: 'all'
// }
// }
// }
// },
resolve: {
extensions: ['.js', '.ts', '.tsx']
},
devtool: 'source-map',//不使用eval方便调试
module: {
rules: [
{
test: /\.(tsx|ts)?$/,
use: 'awesome-typescript-loader'
},
// css "style-loader"
{
test: /\.(sass|scss|css)$/,
use: [MiniCssExtractPlugin.loader, 'css-loader',
{
loader: 'sass-loader',
options: {
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: {
plugins: [
require('autoprefixer')({ browsers: ['last 2 versions', '> 1%', "IE 9"] })
]
}
}
]
},
// static assets
{
test: /\.html$/,
use: 'html-loader'
},
{
test: /\.(jpg|png|gif)$/, use: [
{
loader: 'file-loader',
options: {
name: '[name]-[hash].[ext]',
outputPath: './images/',
useRelativePath: false
}
},
]
},
{
test: /\.js$/,
include: /\/node_modules\//,
loader: 'es3ify'
}
],
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
})
],
devServer: {
contentBase: sourcePath,
hot: true,
stats: {
warnings: false
},
// proxy: {
// '/shengou/*': {
// target: 'http://192.168.1.81:8011',
// changeOrigin: true,
// secure: false
// },
// '/ajax/loadRangeNew*': {
// target: 'http://192.168.1.84:8011',
// changeOrigin: true,
// secure: false
// },
// },
before(app) {
Mocker(app, Path.resolve('mock/index.js'))
},
disableHostCheck: true
},
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
ie8: true
},
sourceMap: true
})
]
},
node: {
fs: 'empty'
}
};
if (options.mode == 'production') {
config.resolve.alias = {
//如果你在移动端用到了onTouchTap事件
// 'react-tap-event-plugin': 'anujs/lib/injectTapEventPlugin',
'react': 'anujs/dist/ReactIE',
'react-dom': 'anujs/dist/ReactIE',
'@reach/router': 'anujs/dist/Router'
}
}
return config;
}