Skip to content

Commit 9b1f9ef

Browse files
authored
feat(build): allow individual components to be build separately only
Individual components will have their .css/.js file generated under /dist/components, but are not included in semantic.css and semantic.js. This is useful for including components in your project only if you need them, while keeping the file size of the main .css/.js file down. To accomplish this, simply add a new array to your semantic.json: ``` "individuals": [ form, modal, step ] ``` Don't forget to remove these items from the "components" array. This change should be fully backwards compatible. It only changes the src variable if an "individuals" array has been defined in the config.
1 parent 09e6d28 commit 9b1f9ef

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

tasks/build/css.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ function buildCSS(src, type, config, opts, callback) {
127127
src = config.paths.source.definitions + '/**/' + config.globs.components + '.less';
128128
}
129129

130+
if (globs.individuals !== undefined) {
131+
const individuals = config.globs.individuals.replace('{','');
132+
const components = config.globs.components.replace('}',',').concat(individuals);
133+
134+
src = config.paths.source.definitions + '/**/' + components + '.less';
135+
}
136+
130137
const buildUncompressed = () => build(src, type, false, config, opts);
131138
buildUncompressed.displayName = 'Building uncompressed CSS';
132139

tasks/build/javascript.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ function buildJS(src, type, config, callback) {
9999
src = config.paths.source.definitions + '/**/' + config.globs.components + (config.globs.ignored || '') + '.js';
100100
}
101101

102+
if (globs.individuals !== undefined) {
103+
const individuals = config.globs.individuals.replace('{','');
104+
const components = config.globs.components.replace('}',',').concat(individuals);
105+
106+
src = config.paths.source.definitions + '/**/' + components + (config.globs.ignored || '') + '.js';
107+
}
108+
102109
// copy source javascript
103110
const js = () => build(src, type, config);
104111
js.displayName = "Building un/compressed Javascript";

tasks/config/project/config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ module.exports = {
135135
: '{' + defaults.components.join(',') + '}'
136136
;
137137

138+
// components that should be built, but excluded from main .css/.js files
139+
config.globs.individuals = (typeof config.individuals == 'object')
140+
? (config.individuals.length > 1)
141+
? '{' + config.individuals.join(',') + '}'
142+
: config.individuals[0]
143+
: undefined
144+
;
145+
138146
return config;
139147

140148
}

0 commit comments

Comments
 (0)