-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.babel.js
91 lines (83 loc) · 2.01 KB
/
webpack.config.babel.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
import path from 'path'
import fs from 'fs'
// import webpack from 'webpack'
const rootPath = __dirname
const srcPath = path.join(rootPath, 'src')
const distPath = path.join(rootPath, 'lib')
const modulesPath = path.join(rootPath, 'node_modules')
let nodeModules = {}
fs.readdirSync(modulesPath)
.filter(x => ['.bin'].indexOf(x) === -1)
.forEach(mod => (nodeModules[mod] = 'commonjs ' + mod))
let exportConfigs = {}
fs.readdirSync('./src/config/')
.filter(file => file.match(/.*\.js$/))
.map(file => (exportConfigs[`config/${file.replace(/\.js$/, '')}`] = `${srcPath}/config/${file}`))
export default {
target: 'node',
cache: true,
context: srcPath,
node: {
__filename: false,
__dirname: false
},
entry: Object.assign({}, exportConfigs, {
'index': ['babel-polyfill', path.join(srcPath, 'index.js')]
}),
output: {
path: distPath,
filename: '[name].js',
// publicPath: 'http://localhost:3000/static/'
publicPath: ''
// publicPath: `http://localhost:${port}/`
},
plugins: [
/*
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
// remove `console.*`
},
output: {
comments: false
}
})
*/
],
stats: {
// Nice colored output
colors: true
},
module: {
loaders: [{
test: /\.json$/,
loader: 'json'
}, {
test: /\.jsx?$/,
loader: 'babel',
query: {
cacheDirectory: true
},
include: srcPath
}],
noParse: [
// allow some js include dynamic require
// webpack(2.1.beta) not support dynamic require yet
// like: getMockRoutes
/\.noparse\.jsx?/
// 'request/index.js'
// 'react/dist/react.js',
// 'react-dom/dist/react-dom.js'
],
// disable Critical dependency warnning
exprContextCritical: false
},
resolve: {
// require('file') => require('file.coffee')
extensions: ['.js', '.jsx', '.json', '.coffee'],
// optimize jquery
alias: {
}
},
externals: nodeModules
}