-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathenvironment.js
130 lines (81 loc) · 2.66 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
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
'use strict';
//
// Require some modules
//
var Mincer = require('..');
//
// Configure Mincers logger, by default, all
// messages are going to the middle of nowhere
//
Mincer.logger.use(console);
//
// Create and export environment
//
var environment = module.exports = new Mincer.Environment(__dirname);
//
// Enable source maps support
//
environment.enable('source_maps');
// environment.sourceRoot = '/'; // use to cheat nesting level in dev tools
//
// Configure environment load paths (where to find ssets)
//
environment.appendPath('assets/javascripts');
environment.appendPath('assets/stylesheets');
environment.appendPath('assets/images');
environment.appendPath('vendor');
//
// Cache compiled assets.
//
// You want this to be enabled on your dev/staging/production environment.
// In order to enable it, uncomment following line. We keep it disabled in
// order to quick-test new featurees without bumping up Mincer's version.
//
// environment.cache = new Mincer.FileStore(path.join(__dirname, 'cache'));
//
// Define environment essential *_path helper that will be available in the
// processed assets. See `assets/stylesheets/app.css.ejs` for example.
//
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;
});
environment.enable('autoprefixer');
//
// 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));
//
// "Th-th-th-that's all folks!"