This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
/
webpack.config.js
84 lines (78 loc) · 2.22 KB
/
webpack.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var fs = require('fs')
var path = require('path')
var webpack = require('webpack')
var CopyWebpackPlugin = require('copy-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var FlowStatusWebpackPlugin = require('flow-status-webpack-plugin')
var dependencies = require('./package.json').dependencies
var resolveRoot = process.env.NODE_PATH
? process.env.NODE_PATH.split(';')
: []
require('dotenv').config({
path: process.env.DOTENV || '.env.example'
})
var examples = fs.readdirSync(path.join(__dirname, '/examples'))
.map((name) => ({name, url: `/examples/${name}`}))
var plugins = [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
BWD_EXAMPLES: JSON.stringify(
(process.env.BWD_EXAMPLES ? JSON.parse(process.env.BWD_EXAMPLES) : []).concat(examples)
)
}
}),
new webpack.optimize.CommonsChunkPlugin('core', 'js/core.js'),
new ExtractTextPlugin('css/[name].css', {allChunks: true}),
new CopyWebpackPlugin([
{from: 'src/views'},
{from: 'CNAME'},
{from: 'examples', to: 'examples'}
])
]
if (process.env.NODE_ENV === 'production') {
plugins.push(new webpack.optimize.UglifyJsPlugin({warnings: false}))
} else {
plugins.push(new FlowStatusWebpackPlugin({
onError: console.error.bind(console),
binaryPath: require('flow-bin')
}))
}
module.exports = {
entry: {
core: Object.keys(dependencies),
main: 'main'
},
output: {
path: 'dist/',
publicPath: '',
filename: 'js/[name].js'
},
module: {
loaders: [
{test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'},
{test: /\.json$/, loader: 'json5-loader'},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract(
'style-loader',
'css-loader?-url' + (process.env.NODE_ENV === 'production' ? ',minimize' : '')
)
}
]
},
resolve: {
root: resolveRoot.concat(path.join(__dirname, 'node_modules')),
modulesDirectories: [
'src',
'src/js',
__dirname,
'node_modules'
],
extensions: ['.js', '.css', '']
},
resolveLoader: {
root: resolveRoot.concat(path.join(__dirname, 'node_modules'))
},
plugins: plugins
}