-
-
Notifications
You must be signed in to change notification settings - Fork 485
/
bootstrap.styles.loader.js
89 lines (74 loc) · 2.19 KB
/
bootstrap.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
/* eslint func-names: 0 */
import loaderUtils from 'loader-utils';
import processModules from './utils/processModules';
import getFontsPath from './utils/getFontsPath';
import createUserImport from './utils/createUserImport';
import createBootstrapImport from './utils/createBootstrapImport';
import logger from './utils/logger';
/**
* Bootstrap SASS styles loader
*
* @returns {string}
*/
module.exports = function() {
if (this.cacheable) this.cacheable();
logger.debug('Styles input config:', '\n', this.query);
const config = loaderUtils.getOptions(this) || {};
const bootstrapVersion = parseInt(config.bootstrapVersion, 10);
const {
styles,
bootstrapRelPath,
useFlexbox,
isBeta,
useCustomIconFontPath,
preBootstrapCustomizations,
bootstrapCustomizations,
appStyles,
} = config;
const processedStyles = [];
if (bootstrapVersion === 4 && useFlexbox) {
processedStyles.push('$enable-flex: true;');
}
if (styles.indexOf('mixins') > -1) {
processedStyles.push(
createBootstrapImport('mixins', bootstrapVersion, bootstrapRelPath),
);
}
if (preBootstrapCustomizations) {
processedStyles.push(
createUserImport(preBootstrapCustomizations, this),
);
}
if (bootstrapVersion === 4 && isBeta === true) {
processedStyles.push(
createBootstrapImport('functions', bootstrapVersion, bootstrapRelPath),
);
}
processedStyles.push(
createBootstrapImport('variables', bootstrapVersion, bootstrapRelPath),
);
if (bootstrapVersion === 3 && !useCustomIconFontPath) {
processedStyles.push(
`$icon-font-path: "${getFontsPath(bootstrapRelPath, this)}";`,
);
}
if (bootstrapCustomizations) {
processedStyles.push(
createUserImport(bootstrapCustomizations, this),
);
}
const bootstrapStyles = (
processModules(styles, bootstrapVersion, bootstrapRelPath)
);
const userStyles = (
appStyles ? createUserImport(appStyles, this) : ''
);
const stylesOutput = (
processedStyles
.concat(bootstrapStyles, userStyles)
.map(style => `${style.replace(/\\/g, '/')}\n`)
.join('')
);
logger.debug('Styles output:', '\n', stylesOutput);
return stylesOutput;
};