|
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
|
|
|
port: 8075, |
|
30
|
|
|
hot: true, |
|
31
|
|
|
noInfo: true, |
|
32
|
|
|
overlay: { |
|
33
|
|
|
warnings: false, |
|
34
|
|
|
errors: true |
|
35
|
|
|
}, |
|
36
|
|
|
historyApiFallback: true |
|
37
|
|
|
// headers: { |
|
38
|
|
|
// 'Access-Control-Allow-Origin': '*' |
|
39
|
|
|
// } |
|
40
|
|
|
}, |
|
41
|
|
|
devtool: isProduction ? false : 'cheap-module-source-map', |
|
42
|
|
|
module: { |
|
43
|
|
|
rules: [{ |
|
44
|
|
|
test: /\.jsx?$/, |
|
45
|
|
|
enforce: 'pre', |
|
46
|
|
|
use: 'standard-loader', |
|
47
|
|
|
exclude: [/node_modules/] |
|
48
|
|
|
}, { |
|
49
|
|
|
test: [/\.js$/, /\.jsx$/], |
|
50
|
|
|
loader: 'babel-loader', |
|
51
|
|
|
options: { |
|
52
|
|
|
presets: ['env', 'react'], |
|
53
|
|
|
plugins: ['transform-object-rest-spread', 'transform-class-properties', 'transform-object-assign'] |
|
54
|
|
|
}, |
|
55
|
|
|
exclude: [/node_modules/] |
|
56
|
|
|
}, { |
|
57
|
|
|
test: /\.css$/, |
|
58
|
|
|
use: ['style-loader', 'css-loader'] |
|
59
|
|
|
}, { |
|
60
|
|
|
test: /\.styl$/, |
|
61
|
|
|
use: ['style-loader', 'css-loader', 'stylus-loader'] |
|
62
|
|
|
}, { |
|
63
|
|
|
test: /\.(jpg|png|svg)$/, |
|
64
|
|
|
loader: 'url-loader', |
|
65
|
|
|
options: { |
|
66
|
|
|
limit: 25000 |
|
67
|
|
|
} |
|
68
|
|
|
}] |
|
69
|
|
|
}, |
|
70
|
|
|
resolve: { |
|
71
|
|
|
extensions: ['.js', '.jsx'] |
|
72
|
|
|
}, |
|
73
|
|
|
plugins: [ |
|
74
|
|
|
...[], // generic plugins always present |
|
75
|
|
|
...(isProduction |
|
76
|
|
|
? [ // production specific plugins |
|
77
|
|
|
new webpack.DefinePlugin({ |
|
78
|
|
|
'process.env': { 'NODE_ENV': JSON.stringify('production') } |
|
79
|
|
|
}) |
|
80
|
|
|
// new webpack.optimize.UglifyJsPlugin({ |
|
81
|
|
|
// compress: { warnings: false } |
|
82
|
|
|
// }) |
|
83
|
|
|
] |
|
84
|
|
|
: [ // development specific plugins |
|
85
|
|
|
] |
|
86
|
|
|
) |
|
87
|
|
|
] |
|
88
|
|
|
} |
|
89
|
|
|
|