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