-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnwb.config.js
67 lines (58 loc) · 1.7 KB
/
nwb.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
var path = require('path')
var BundleTracker = require('webpack-bundle-tracker')
/**
* Entry point configuration.
*
* This is where you should configure your webpack entry points, for example, a different entry point per page.
*/
const ENTRIES = {
index: './src/index.js',
}
const SHARED_ENTRIES = [
'./node_modules/nwb/polyfills.js',
]
/**
* nwb config
*/
module.exports = function({command}) {
const isDevelopment = command.startsWith('serve')
/* Set config */
let config = {
type: 'react-app',
}
config.webpack = {
config(webpackConfig) {
/* Convert webpackConfig.entry from array to object format */
let sharedEntries = SHARED_ENTRIES
if (isDevelopment) {
// React Hot Loader's patch module needs to run before your app
sharedEntries = [
'react-hot-loader/patch',
...SHARED_ENTRIES,
'./node_modules/webpack-dev-server/client/index.js?http://localhost:3000/',
'./node_modules/webpack/hot/only-dev-server.js',
]
}
// Set new entry configuration
webpackConfig.entry = {}
Object.keys(ENTRIES).forEach((entryKey) => {
webpackConfig.entry[entryKey] = [...sharedEntries, ENTRIES[entryKey]]
})
return webpackConfig
},
extra: {
output: {
path: path.resolve('./dist/webpack_bundles/'),
},
plugins: [
new BundleTracker({filename: './webpack-stats.json'}),
],
},
publicPath: isDevelopment ? 'http://localhost:3000/' : '/static/webpack_bundles/',
}
if (isDevelopment) {
// Only include react-hot-loader into babel and set publicPath if development
config.babel = {plugins: 'react-hot-loader/babel'}
}
return config
}