This repository has been archived by the owner on Feb 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
88 lines (77 loc) · 2.61 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
const path = require('path')
const appRoot = require('app-root-path').toString()
const webpack = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const nodeExternals = require('webpack-node-externals')
const ENV_DEFAULT = {
analyzer: false,
}
module.exports = (env = ENV_DEFAULT) => {
const config = {
// 因为希望把压缩代码放在 gulp 中来做,因此虽然是发布构建,但不能设置为 `production`
mode: 'none',
// entry 在 gulp 中指定
output: {
path: path.join(appRoot, 'lib'),
filename: 'index.js',
libraryTarget: 'commonjs2',
},
resolve: {
extensions: ['.json', '.js', '.jsx', '.ts', '.tsx', '.css', '.scss'],
},
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.tsx?$/,
include: path.join(__dirname, 'src'),
use: [
{
loader: 'babel-loader',
},
{
loader: 'ts-loader',
options: {
onlyCompileBundledFiles: true,
},
},
],
},
{
test: /\.scss$/,
include: path.join(__dirname, 'src'),
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
options: {
sassOptions: {
outputStyle: 'expanded',
},
},
},
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: 'index.css',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
__DEV__: false,
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
],
}
if (env.analyzer) {
config.plugins.unshift(new BundleAnalyzerPlugin())
}
return config
}