-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.server.coffee
69 lines (54 loc) · 1.4 KB
/
webpack.server.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
{ BannerPlugin } = require 'webpack'
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Options
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~
# publicPath: {string}
# devtool: yes|no
# optiImgs: yes|no
module.exports = (options) ->
options = options or {}
# ~~~~~ Output ~~~~~~~
_publicPath =
if options.publicPath then options.publicPath
else "/static/"
output =
path: "__build__"
filename: "server.js"
libraryTarget: "commonjs2"
publicPath: _publicPath
# ~~~~~ Devtool ~~~~~~~
devtool = if options.devtool then "sourcemap"
# ~~~~~ Loaders ~~~~~~~~
commonLoaders = [
test: /\.coffee$/,
loader: 'coffee!cjsx',
exclude: "node_modules"
,
test: /\.svg/
loader: 'file'
]
_imgLoader = [
test: /\.(jpe?g|png|gif)$/
loader:
if options.optiImgs
"file!image-webpack?optimizationLevel=7&interlaced=false"
else 'file'
]
loaders = commonLoaders.concat(_imgLoader)
# ~~~~~ Plugins ~~~~~~~
plugins = []
if options.devtool
plugins.push new BannerPlugin 'require("source-map-support").install();',
raw: true, entryOnly: false
# ~~~~~~ Config returned ~~~~~~~
entry: './server.coffee'
target: 'node'
context: __dirname
output: output
resolve:
extensions: ['', '.webpack.js', '.web.js', '.js', '.coffee']
externals: /^[a-z][a-z\.\-0-9]*$/
devtool: devtool
module:
loaders: loaders
plugins: plugins