forked from rip-tyang/site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.coffee
89 lines (78 loc) · 2.11 KB
/
webpack.config.coffee
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
webpack = require 'webpack'
path = require 'path'
nib = require 'nib'
stylus = require 'stylus'
ManifestPlugin = require 'webpack-manifest-plugin'
banner = 'Copyright 2015 Thomas Yang http://thomas-yang.me/'
paths =
src: path.join(__dirname, 'src')
dest: path.join(__dirname, 'dist')
debugPlugins = [
new webpack.HotModuleReplacementPlugin()
new webpack.BannerPlugin(banner)
]
productionPlugins = [
new ManifestPlugin()
new webpack.BannerPlugin(banner)
new webpack.optimize.UglifyJsPlugin({
sourceMap: false
compress: true
mangle: true
})
]
baseOption =
output:
path: paths.dest
resolve:
# you can now require('file') instead of require('file.coffee')
extensions: ['', '.js', '.json', '.coffee', '.css', '.styl']
module:
loaders: [
{
test: /\.coffee$/
exclude: /node_modules/
loader: 'coffee-loader'
}
{
test: /\.styl$/
loader: 'style-loader!css-loader!stylus-loader'
}
{
test: /\.(eot|ttf|woff|otf|svg)$/
loader: 'url?limit=100000'
}
]
stylus:
use: [nib()]
define:
'inline-url': stylus.url
paths: [__dirname + '/src']
limit: false
makeEntry = (obj) ->
throw Error 'no entry files' unless obj.entry?.length > 0
r = {}
obj.entry.forEach (e) -> r[e] = ["#{paths.src}/coffee/#{e}.coffee"]
if obj.isDebug
hotServer = 'webpack/hot/dev-server'
reloadServer = "webpack-dev-server/client?http://localhost:#{obj.port}"
for k, v of r
v.unshift reloadServer
v.unshift hotServer
r
createOption = (obj = {}) ->
throw Error 'specify how to build: debug or production' unless obj.build?
obj.isDebug = obj.build isnt 'production'
obj.port = obj.port || 5000
option = Object.create baseOption
option.entry = makeEntry obj
if obj.isDebug
option.watch = true
option.debug = true
option.devtool = 'cheap-module-source-map'
option.output.filename = '[name].js'
option.plugins = debugPlugins
else
option.output.filename = '[name].[hash].js'
option.plugins = productionPlugins
option
module.exports = createOption