forked from BKWLD/decoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.coffee
211 lines (168 loc) · 6.3 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# Inspect how webpack is being run
minify = '-p' in process.argv # Compiling for production
# Deps
webpack = require 'webpack'
autoprefixer = require 'autoprefixer'
moment = require 'moment'
ExtractText = require 'extract-text-webpack-plugin'
_ = require 'lodash'
# Autoprefixer config
# https://github.com/ai/browserslist#queries
autoprefixerBrowsers = [
'last 2 versions'
'ie >= 10'
]
# Webpack configuration
config =
# Set the dir to look for entry files
context: "#{process.cwd()}/assets"
# When minifying, use the autorunning entry point. Otherwise, return the main
# Decoy module that has a public API for configuration.
entry: index: if minify then 'js/index.js' else 'js/decoy.js'
# Where to put the files
output:
path: "./dist"
publicPath: '/assets/decoy/'
filename: if minify then '[name].min.js' else '[name].js'
chunkFilename: if minify then '[id].[hash:8].js' else '[id].js'
# Make a UMD module
library: 'decoy'
libraryTarget: 'umd'
umdNamedDefine: true
# Setup properties that are set later (With less indentation)
module: {}
# Configure what shows up in the terminal output
stats:
children: false # Hides the "extract-text-webpack-plugin" messages
assets: true
colors: true
version: false
hash: false
timings: true
chunks: false
chunkModules: false
# Modules that shouldn't get parsed for dependencies. These will probably be
# used in tandem with using aliases to point at built versions of the modules.
config.module.noParse = [
# Using a built version of pixijs for Decoy to fix issues where it errors on
# trying to use node's `fs`. Another solution could have been to set
# node: { fs: 'empty' }
# https://github.com/pixijs/pixi.js/issues/1854#issuecomment-156074530
# https://github.com/pixijs/pixi.js/issues/2078#issuecomment-137297392
/bin\/pixi\.js$/
]
# ##############################################################################
# Resolve - Where to find files
# ##############################################################################
config.resolve =
root: "#{process.cwd()}/assets"
# Look for modules in the vendor directory as well as npm's directory. The
# vendor directory is used for third party modules that are committed to the
# repo, like things that can't be installed via npm. For example, Modernizr.
modulesDirectories: ['workbench', 'vendor', 'node_modules']
# Add coffee to the list of optional extensions
extensions: ['', '.js', '.coffee', '.vue']
# Aliases for common libraries
alias:
velocity: 'velocity-animate'
underscore: 'lodash'
# Decoy aliases
bkwld: 'bkwld-js-library'
bootstrap: 'bootstrap-sass'
jcrop: 'jcrop-0.9.12'
pixi: 'pixi.js/bin/pixi.js'
'eventEmitter/EventEmitter': 'wolfy87-eventemitter'
'bootstrap-timepicker': 'bootstrap-timepicker/js/bootstrap-timepicker'
# ##############################################################################
# Loaders - File transmogrifying
# ##############################################################################
config.module.loaders = [
# Coffeescript #
{ test: /\.coffee$/, loader: 'coffee-loader' }
# HTML #
{ test: /\.html$/, loader: 'html-loader' }
# Images #
# If files are smaller than the limit, becomes a data-url. Otherwise,
# copies the files into dist and returns the hashed URL. Also runs imagemin.
{
test: /\.(png|gif|jpe?g|svg)$/
loaders: [
'url?limit=10000&name=img/[hash:8].[ext]'
'img?progressive=true'
]
}
# Fonts #
# Not using the url-loader because serving multiple formats of a font would
# mean inlining multiple formats that are unncessary for a given user.
{
test: /\.(eot|ttf|otf|woff|woff2)$/
loader: 'file-loader?name=fonts/[hash:8].[ext]'
}
# JSON #
{ test: /\.json$/, loader: 'json-loader' }
# CSS #
{
test: /\.css$/
loader:
ExtractText.extract 'css-loader?-autoprefixer'
}
# Sass #
{
test: /\.scss$/
loader:
ExtractText.extract [
'css-loader?sourceMap'
'postcss-loader'
'sass-loader?sourceMap'
'import-glob-loader'
].join('!')
}
# jQuery #
# This adds jquery to window globals so that it's useable from the console
# but also so that it can be found by jQuery plugins, like Velocity. This
# "test" syntax is used to find the file in node_modules, the "expose"
# loader's examples ("require.resolve") don't work because node is looking
# in the app node_modules.
{ test: /jquery\.js$/, loader: 'expose-loader?$!expose?jQuery' }
# jQuery plugins #
# Make sure jQuery is loaded before Velocity
{
test: /(velocity|redactor\/redactor)\.js$/,
loader: 'imports-loader?$=jquery'
}
]
# ############################################################################
# Plugins - Register extra functionality
# ############################################################################
config.plugins = [
# Required config for ExtractText to tell it what to name css files. Setting
# "allChunks" so that CSS referenced in chunked code splits still show up
# in here. Otherwise, we would need webpack to DOM insert the styles on
# which doesn't play nice with sourcemaps.
new ExtractText (if minify then '[name].min.css' else '[name].css'),
allChunks: true
# Add some branding to all compiled JS files
new webpack.BannerPlugin "📝 Bukwild 💾 #{moment().format('M.D.YY')} 👍"
]
# Minify only (`webpack -p`) plugins.
if minify then config.plugins = config.plugins.concat [
# Turn off warnings during minifcation. They aren't particularly helpfull.
new webpack.optimize.UglifyJsPlugin compress: warnings: false
# Make small ids
new webpack.optimize.OccurenceOrderPlugin()
# Try and remove duplicate modules
new webpack.optimize.DedupePlugin()
]
# ##############################################################################
# Misc config - Mostly loader options
# ##############################################################################
_.assign config,
# Configure autoprefixer using browserslist rules
postcss: -> [ autoprefixer( browsers: autoprefixerBrowsers ) ]
# Increase precision of math in SASS for Bootstrap
# https://github.com/twbs/bootstrap-sass#sass-number-precision
sassLoader: precision: 10
# ##############################################################################
# Export
# ##############################################################################
module.exports = config