This repository was archived by the owner on Jul 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.js
More file actions
59 lines (57 loc) · 1.85 KB
/
Copy pathwebpack.config.js
File metadata and controls
59 lines (57 loc) · 1.85 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const workSpaceDir = path.resolve(__dirname);
/** 使用 CDN 的第三方库 */
const externals = {
react: 'React',
antd: 'antd',
marked: 'marked',
'react-dom': 'ReactDOM',
'react-router-dom': 'ReactRouterDOM',
axios: "axios",
}
module.exports = (env) => {
if (!env) { env = {production: false, analyze: false};}
console.log("Compile config:", env);
return ({
entry: path.join(workSpaceDir, 'src/index.tsx'),
devServer:{
port: 3030,
open: true,
historyApiFallback: true
},
output: {
path: path.join(workSpaceDir, 'dist/js'),
filename: env.production ? 'bundle.min.js': 'bundle.js'
},
module: {
rules: [
{test:/\.css$/,use:["style-loader","css-loader"]},
{ test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/ },
{ test: /\.styl$/, use: ['style-loader', 'css-loader', 'stylus-loader'] },
{ test:/\.(md|txt)$/, use: "raw-loader" },
{ test:/\.ya?ml$/, use: [ "json-loader", "yaml-loader" ] }
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'dist/index.debug.html'
}),
new webpack.HotModuleReplacementPlugin(),
env.analyze ? new BundleAnalyzerPlugin(): new webpack.DefinePlugin({}),
],
resolve: {
extensions: [ '.tsx', '.ts', '.js', 'yaml' ],
plugins: [
new TsconfigPathsPlugin({configFile: path.join(workSpaceDir, 'tsconfig.json')})
],
alias: { config: path.join(__dirname, "configs/config." + (env.production ? "release": "debug") + ".yaml") }
},
devtool: env.production ? "" : "source-map",
mode: env.production ? "production" : "development",
externals: env.production ? externals : {},
});
};