1
|
|
|
const webpack = require('webpack') |
2
|
|
|
const path = require('path') |
3
|
|
|
const glob = require('glob') |
4
|
|
|
const isProduction = process.env.NODE_ENV === 'production' |
5
|
|
|
|
6
|
|
|
module.exports = { |
7
|
|
|
entry: { |
8
|
|
|
libJs: isProduction ? './src/index.js' : './src/index.dev.js', |
9
|
|
|
libStyle: glob.sync('./src/**/*.styl') |
10
|
|
|
}, |
11
|
|
|
output: { |
12
|
|
|
path: path.resolve(__dirname, 'dist'), |
13
|
|
|
filename: isProduction ? 'tracim_frontend_lib.js' : 'tracim_frontend_lib.dev.js', |
14
|
|
|
pathinfo: !isProduction, |
15
|
|
|
library: isProduction ? 'tracim_frontend_lib' : undefined, |
16
|
|
|
libraryTarget: isProduction ? 'umd' : undefined, |
17
|
|
|
umdNamedDefine: isProduction ? true : undefined |
18
|
|
|
}, |
19
|
|
|
externals: isProduction |
20
|
|
|
? { |
21
|
|
|
react: {commonjs: 'react', commonjs2: 'react', amd: 'react', root: '_'}, |
22
|
|
|
'react-dom': {commonjs: 'react-dom', commonjs2: 'react-dom', amd: 'react-dom', root: '_'}, |
23
|
|
|
'react-i18next': {commonjs: 'react-i18next', commonjs2: 'react-i18next', amd: 'react-i18next', root: '_'}, |
24
|
|
|
classnames: {commonjs: 'classnames', commonjs2: 'classnames', amd: 'classnames', root: '_'}, |
25
|
|
|
'prop-types': {commonjs: 'prop-types', commonjs2: 'prop-types', amd: 'prop-types', root: '_'}, |
26
|
|
|
radium: {commonjs: 'radium', commonjs2: 'radium', amd: 'radium', root: '_'} |
27
|
|
|
} |
28
|
|
|
: {}, |
29
|
|
|
devServer: { |
30
|
|
|
contentBase: path.join(__dirname, 'dist/'), |
31
|
|
|
port: 8070, |
32
|
|
|
hot: true, |
33
|
|
|
noInfo: true, |
34
|
|
|
overlay: { |
35
|
|
|
warnings: false, |
36
|
|
|
errors: true |
37
|
|
|
}, |
38
|
|
|
historyApiFallback: true |
39
|
|
|
// headers: { |
40
|
|
|
// 'Access-Control-Allow-Origin': '*' |
41
|
|
|
// } |
42
|
|
|
}, |
43
|
|
|
devtool: isProduction ? false : 'cheap-module-source-map', |
44
|
|
|
module: { |
45
|
|
|
rules: [ |
46
|
|
|
isProduction |
47
|
|
|
? {} |
48
|
|
|
: { |
49
|
|
|
test: /\.jsx?$/, |
50
|
|
|
enforce: 'pre', |
51
|
|
|
use: 'standard-loader', |
52
|
|
|
exclude: [/node_modules/] |
53
|
|
|
}, { |
54
|
|
|
test: [/\.js$/, /\.jsx$/], |
55
|
|
|
loader: 'babel-loader', |
56
|
|
|
options: { |
57
|
|
|
presets: ['env', 'react'], |
58
|
|
|
plugins: ['transform-object-rest-spread', 'transform-class-properties', 'transform-object-assign'] |
59
|
|
|
}, |
60
|
|
|
exclude: [/node_modules/] |
61
|
|
|
}, { |
62
|
|
|
test: /\.css$/, |
63
|
|
|
use: ['style-loader', 'css-loader'] |
64
|
|
|
}, { |
65
|
|
|
test: /\.styl$/, |
66
|
|
|
use: ['style-loader', 'css-loader', 'stylus-loader'] |
67
|
|
|
// }, { |
68
|
|
|
// test: /\.(jpg|png|svg)$/, |
69
|
|
|
// loader: 'url-loader', |
70
|
|
|
// options: { |
71
|
|
|
// limit: 25000 |
72
|
|
|
// } |
73
|
|
|
}] |
74
|
|
|
}, |
75
|
|
|
resolve: { |
76
|
|
|
extensions: ['.js', '.jsx'] |
77
|
|
|
}, |
78
|
|
|
plugins:[ |
79
|
|
|
...[ |
80
|
|
|
new webpack.optimize.CommonsChunkPlugin({ |
81
|
|
|
name: 'libStyle', |
82
|
|
|
filename: 'tracim_frontend_lib.style.js' |
83
|
|
|
}) |
84
|
|
|
], // generic plugins always present |
85
|
|
|
...(isProduction |
86
|
|
|
? [ // production specific plugins |
87
|
|
|
new webpack.DefinePlugin({ |
88
|
|
|
'process.env': { 'NODE_ENV': JSON.stringify('production') } |
89
|
|
|
}), |
90
|
|
|
new webpack.optimize.UglifyJsPlugin({ |
91
|
|
|
compress: { warnings: false } |
92
|
|
|
}) |
93
|
|
|
] |
94
|
|
|
: [] // development specific plugins |
95
|
|
|
) |
96
|
|
|
] |
97
|
|
|
} |
98
|
|
|
|