forked from Meteor-Community-Packages/meteor-scss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.js
48 lines (38 loc) · 1.38 KB
/
package.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
Package.describe({
summary: "Style with attitude."
});
Npm.depends({'node-sass': '0.5.1'});
var scss_handler = function (bundle, source_path, serve_path, where) {
var path = Npm.require('path');
// Return if it's a partial, we don't want to output those as css files.
if (path.basename(source_path)[0] === '_') return;
var fs = Npm.require('fs');
var sass = Npm.require('node-sass');
serve_path = serve_path + '.css';
var options = {
includePaths: [path.resolve(source_path, '..')] // for @import
};
var contents = fs.readFileSync(source_path, 'utf8');
try {
var css = sass.renderSync(contents.toString('utf8'), options);
bundle.add_resource({
type: "css",
path: serve_path,
data: new Buffer(css),
where: where
});
} catch (e) {
// sass.render() is supposed to report any errors via its
// callback. But sometimes, it throws them instead. This is
// probably a bug in sass. Be prepared for either behavior.
return bundle.error(source_path + ": Sass compiler error: " + e.message);
}
};
Package.register_extension("scss", scss_handler);
// Register scssimport files with the dependency watcher, without actually
// processing them.
Package.register_extension("scssimport", function () {});
Package.on_test(function (api) {
api.use('test-helpers');
api.add_files(['scss_tests.scss', 'scss_tests.js'], 'client');
});