-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathwebpack.config.js
110 lines (105 loc) · 2.85 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
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
// 读取全局配置环境
const env = String.prototype.trim.call(process.env.WEBPACK_ENV) || 'production';
const entry = {
develop: './examples.js',
production: './src/index.js',
examples: './examples.js'
}
const output = {
develop: {
filename: 'examples.js',
path: path.resolve(__dirname, 'examples'),
publicPath: './'
},
production: {
filename: 'react-toast-mobile.js',
path: path.resolve(__dirname, 'lib'),
publicPath: './',
libraryTarget: 'umd',
library: 'ReactToastMobile'
},
examples: {
filename: 'examples.js',
path: path.resolve(__dirname, 'examples'),
publicPath: './'
}
}
const externals = {
develop: {},
examples: {
'react': 'React',
'react-dom': 'ReactDOM',
'prop-types': 'PropTypes',
'react-transition-group': 'ReactTransitionGroup',
'react-toast-mobile': 'ReactToastMobile',
},
production: {
'react': {
commonjs: 'react',
commonjs2: 'react',
amd: 'react',
root: 'React'
},
'react-dom': {
commonjs: 'react-dom',
commonjs2: 'react-dom',
amd: 'react-dom',
root: 'ReactDOM'
},
'prop-types': {
commonjs: 'prop-types',
commonjs2: 'prop-types',
amd: 'prop-types',
root: 'PropTypes'
},
'react-transition-group': {
commonjs: 'react-transition-group',
commonjs2: 'react-transition-group',
amd: 'react-transition-group',
root: 'ReactTransitionGroup'
}
}
}
module.exports = {
entry: entry[env],
output: output[env],
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader']
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
publicPath: './',
use: ['css-loader', 'postcss-loader']
})
}, {
test: /\.less$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
publicPath: './',
use: ['css-loader', 'postcss-loader', 'less-loader']
})
}
]
},
// deps
externals: externals[env],
// devserver config
devServer: {
host: '0.0.0.0',
port: 8080,
hot: true,
clientLogLevel: 'warning',
historyApiFallback: true,
disableHostCheck: true,
contentBase: './examples',
publicPath: '/'
},
plugins: [new ExtractTextPlugin('react-toast-mobile.css')]
};