-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathenvironment.js
75 lines (62 loc) · 2.18 KB
/
environment.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
#!/usr/bin/env node
var Mincer = require('mincer');
var utils = require('@utils');
var oldsassFunctions = Mincer.SassEngine.prototype.sassFunctions;
Mincer.SassEngine.prototype.sassFunctions = function (locals) {
var outs = oldsassFunctions.call(this, locals);
for (var i in outs) {
var ni = i.replace('_', '-');
outs[ni] = outs[i];
}
return outs;
}
Mincer.enable('autoprefixer');
var environment = module.exports = new Mincer.Environment(utils.path.resolve('public'));
// environment.enable('source_maps');
environment.appendPath('javascripts');
environment.appendPath('stylesheets');
environment.appendPath('images');
environment.registerHelper('image_url', function (url) {
url = environment.findAsset(url);
return 'url(\'' + '/assets/' + url.digestPath + '\')';
})
environment.ContextClass.defineAssetPath(function (pathname, options) {
var asset = this.environment.findAsset(pathname, options);
if (!asset) {
throw new Error('File ' + pathname + ' not found');
}
return '/assets/' + asset.digestPath;
});
//
// Prepare production-ready environment
//
if (process.env.NODE_ENV === 'production') {
//
// Enable JS and CSS compression
//
environment.jsCompressor = 'uglify';
// (!) use csswring, because csso does not supports sourcemaps
environment.cssCompressor = 'csswring';
//
// In production we assume that assets are not changed between requests,
// so we use cached version of environment. See API docs for details.
//
environment = environment.index;
}
//
// Enable inline macros to embed compile-time variables into code,
// instead of using EJS and chaining extentions. Then you can write things like
//
// var url = "$$ JSON.stringify(asset_path('my_file.js')) $$";
//
// You can set guard regexps as second param. Also you can pass multiple values
// via arrays.
//
Mincer.MacroProcessor.configure(['.js', '.css'] /*, true */);
//
// Mincer rebuilt assets on any dependency file change. But sometime result
// depends on external variables: enviroment type, helper values and so one.
// In this case, you should change enviroment "version" - place there any
// unique string.
//
// enviroment.version = md5(JSON.stringify(your_version_object));