-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack-multi-config.js
executable file
·103 lines (90 loc) · 2.74 KB
/
webpack-multi-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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var config = require('../config')
if(!config.tasks.js) return
var path = require('path')
var pathToUrl = require('./pathToUrl')
var webpack = require('webpack')
var webpackManifest = require('./webpackManifest')
module.exports = function(env) {
var jsSrc = path.resolve(config.root.src, config.tasks.js.src)
var jsDest = path.resolve(config.root.dest, config.tasks.js.dest)
var publicPath = pathToUrl(config.tasks.js.dest, '/')
var extensions = config.tasks.js.extensions.map(function(extension) {
return '.' + extension
})
var rev = config.tasks.production.rev && env === 'production'
var filenamePattern = rev ? '[name]-[hash].js' : '[name].js'
var webpackConfig = {
context: jsSrc,
plugins: [],
resolve: {
root: [
jsSrc,
path.join(__dirname, "..", "gulp", "node_modules")
],
extensions: [''].concat(extensions)
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: config.tasks.js.babel
},
{
test: /\.coffee$/,
loader: "coffee-loader" },
{
test: /\.(coffee\.md|litcoffee)$/,
loader: "coffee-loader?literate"
}
]
}
}
if(env === 'development') {
webpackConfig.devtool = 'inline-source-map'
// Create new entries object with webpack-hot-middleware added
for (var key in config.tasks.js.entries) {
var entry = config.tasks.js.entries[key]
config.tasks.js.entries[key] = ['webpack-hot-middleware/client?&reload=true'].concat(entry)
}
webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin())
}
if(env !== 'test') {
// Karma doesn't need entry points or output settings
webpackConfig.entry = config.tasks.js.entries
webpackConfig.output= {
path: path.normalize(jsDest),
filename: filenamePattern,
publicPath: publicPath
}
if(config.tasks.js.extractSharedJs) {
// Factor out common dependencies into a shared.js
webpackConfig.plugins.push(
new webpack.optimize.CommonsChunkPlugin({
name: 'shared',
filename: filenamePattern,
})
)
}
}
if(env === 'production') {
if(rev) {
webpackConfig.plugins.push(new webpackManifest(publicPath, config.root.dest))
}
webpackConfig.plugins.push(
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
output: { comments: false },
compress: { drop_console: true },
}),
new webpack.NoErrorsPlugin()
)
}
return webpackConfig
}