-
Notifications
You must be signed in to change notification settings - Fork 25
/
bootstrap-sass-styles.loader.js
102 lines (87 loc) · 2.59 KB
/
bootstrap-sass-styles.loader.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
var partials = [
'mixins',
'normalize',
'print',
'glyphicons',
'scaffolding',
'type',
'code',
'grid',
'tables',
'forms',
'buttons',
'component-animations',
'dropdowns',
'button-groups',
'input-groups',
'navs',
'navbar',
'breadcrumbs',
'pagination',
'pager',
'labels',
'badges',
'jumbotron',
'thumbnails',
'alerts',
'progress-bars',
'media',
'list-group',
'panels',
'wells',
'responsive-embed',
'close',
'modals',
'tooltip',
'popovers',
'carousel',
'utilities',
'responsive-utilities'
];
var path = require('path');
var bootstrapSassPath = require('./bootstrapSassPath');
var logger = require('./logger');
function addImportReturnDependency(loader, config, propertyName) {
var fileNameResolved;
var fileName = config[propertyName];
if (fileName && fileName.length > 0) {
fileNameResolved = path.relative(loader.context, fileName);
logger.verbose(config, 'fileName for %s: %s', propertyName, fileNameResolved);
loader.addDependency(fileNameResolved);
return '@import \'' + fileNameResolved + '\';\n';
}
}
module.exports = function(content) {
var source;
var config = this.exec(content, this.resourcePath);
var pathToBootstrapSass = bootstrapSassPath.getPath(this.context);
var relativePathToBootstrapSass = path.relative(this.context, pathToBootstrapSass);
var start = '';
// This needs to be relative
var iconFontPath = '$icon-font-path: \'' + path.join(relativePathToBootstrapSass, 'fonts/bootstrap/') + '\';';
this.cacheable(true);
logger.verbose(config, 'bootstrap-sass location: %s', relativePathToBootstrapSass);
logger.verbose(config, 'Setting: %s', iconFontPath);
if (config.preBootstrapCustomizations) {
start += addImportReturnDependency(this, config, 'preBootstrapCustomizations');
}
start +=
// Absolute paths as these are created at build time.
'@import \'' + path.join(relativePathToBootstrapSass,
'stylesheets/bootstrap/variables') + '\';\n' + iconFontPath + '\n';
if (config.bootstrapCustomizations) {
start += addImportReturnDependency(this, config, 'bootstrapCustomizations');
}
source = start + partials.filter(function(partial) {
return config.styles[partial];
}).map(function(partial) {
return '@import \'' + path.join(relativePathToBootstrapSass, 'stylesheets/bootstrap',
partial) + '\';';
}).join('\n');
if (config.mainSass) {
source += '\n' + addImportReturnDependency(this, config, 'mainSass');
}
source = source.replace(/\\/g, '/');
logger.debug(config, 'Generated scss file is:\n' + source);
return source;
};