Skip to content

Commit

Permalink
feat(build): allow individual components to be build separately only
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hugopeek authored Apr 7, 2020
1 parent 09e6d28 commit 9b1f9ef
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tasks/build/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ function buildCSS(src, type, config, opts, callback) {
src = config.paths.source.definitions + '/**/' + config.globs.components + '.less';
}

if (globs.individuals !== undefined) {
const individuals = config.globs.individuals.replace('{','');
const components = config.globs.components.replace('}',',').concat(individuals);

src = config.paths.source.definitions + '/**/' + components + '.less';
}

const buildUncompressed = () => build(src, type, false, config, opts);
buildUncompressed.displayName = 'Building uncompressed CSS';

Expand Down
7 changes: 7 additions & 0 deletions tasks/build/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ function buildJS(src, type, config, callback) {
src = config.paths.source.definitions + '/**/' + config.globs.components + (config.globs.ignored || '') + '.js';
}

if (globs.individuals !== undefined) {
const individuals = config.globs.individuals.replace('{','');
const components = config.globs.components.replace('}',',').concat(individuals);

src = config.paths.source.definitions + '/**/' + components + (config.globs.ignored || '') + '.js';
}

// copy source javascript
const js = () => build(src, type, config);
js.displayName = "Building un/compressed Javascript";
Expand Down
8 changes: 8 additions & 0 deletions tasks/config/project/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ module.exports = {
: '{' + defaults.components.join(',') + '}'
;

// components that should be built, but excluded from main .css/.js files
config.globs.individuals = (typeof config.individuals == 'object')
? (config.individuals.length > 1)
? '{' + config.individuals.join(',') + '}'
: config.individuals[0]
: undefined
;

return config;

}
Expand Down

0 comments on commit 9b1f9ef

Please sign in to comment.