-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.build.js
106 lines (103 loc) · 2.74 KB
/
webpack.build.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
var path = require('path');
var DoccoPlugin = require('damo-cli-docco-plugin');
const vendors = [
'antd',
'seamless-immutable',
'core-js',
'react',
'prop-types',
'react-dom',
'react-redux',
'react-router',
'react-router-dom',
'react-router-config',
'react-router-redux',
'redux-logger',
'redux-thunk',
'react-intl',
'react-mixin',
'react-addons-pure-render-mixin',
'create-react-class',
'cuid',
'redux',
'redux-promise-middleware',
'react-redux-loading-bar',
'hoist-non-react-statics',
'async-validator',
'isomorphic-fetch',
'events',
'moment',
'querystring',
'url',
'bluebird',
'qs',
'warning',
/rxjs\/*/,
/history\/*/,
/lodash\/*/,
/fbjs\/*/,
/react-router\/*/,
/redux-saga\/*/
];
var webpackOpts = {
entry: {
app: './src/index.js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ['env', 'react'],
plugins: [
'transform-decorators-legacy',
'transform-class-properties',
'add-module-exports',
'transform-object-rest-spread',
[path.resolve(__dirname, 'node_modules/babel-plugin-transform-runtime'), {
polyfill: false,
regenerator: true
}],
[path.resolve(__dirname, 'node_modules/babel-plugin-transform-async-to-module-method'), {
module: 'bluebird',
method: 'coroutine'
}]
],
}
}
}
]
},
output: {
filename: 'beatle.js',
path: path.resolve(__dirname, 'dist/core'),
library: 'beatle',
libraryTarget: 'commonjs2'
},
externals: vendors,
// 开发者工具
// cheap-eval-source-map 打开source
// inline-source-map 调试的时候需要,为每个文件加一个sourcemap的DataUrl,ps:是打包前的每个文件
devtool: '#cheap-source-map',
plugins: [
// define插件,可以做环境变量,代码切分等功能(这里需要拓展)
// new webpack.DefinePlugin({'process.env.NODE_ENV': JSON.stringify('development')}),
// 把静态资源注入html的plugins
// new HtmlWebpackPlugin({template: path.resolve(__dirname, './assets/index.html')}),
// 代码压缩插件
// new webpack.optimize.UglifyJsPlugin({sourceMap: true}),
// js抽离逻辑
// new webpack.optimize.CommonsChunkPlugin({names: ['public', 'vendor'], minChunks: 2})
new DoccoPlugin({dir: './src', output: path.resolve('./dist/docs')})
],
unPlugins: [
'DefinePlugin',
'UglifyJsPlugin',
'CommonsChunkPlugin'
]
};
module.exports = webpackOpts;