What is ember-cli-preprocess-registry?
The ember-cli-preprocess-registry package provides a registry for managing preprocessors in Ember CLI. It allows you to register and manage preprocessors for various types of files, such as JavaScript, CSS, and templates, enabling custom transformations and optimizations during the build process.
What are ember-cli-preprocess-registry's main functionalities?
Registering a preprocessor
This feature allows you to register a custom preprocessor for JavaScript files. The `add` method takes the type of file ('js' in this case), an object with the preprocessor's name, file extension, and a `toTree` function that defines the transformation logic.
const PreprocessRegistry = require('ember-cli-preprocess-registry');
let registry = new PreprocessRegistry();
registry.add('js', {
name: 'my-js-preprocessor',
ext: 'js',
toTree(tree) {
// Custom transformation logic
return tree;
}
});
Using a preprocessor
This feature demonstrates how to use a registered preprocessor. After registering a CSS preprocessor, you can load it using the `load` method, which applies the preprocessor's transformation logic to the provided tree.
const PreprocessRegistry = require('ember-cli-preprocess-registry');
let registry = new PreprocessRegistry();
registry.add('css', {
name: 'my-css-preprocessor',
ext: 'css',
toTree(tree) {
// Custom transformation logic
return tree;
}
});
let cssTree = registry.load('css', someCssTree);
Other packages similar to ember-cli-preprocess-registry
broccoli-persistent-filter
broccoli-persistent-filter is a Broccoli plugin that provides a base class for creating persistent filters. It allows you to create custom filters that can transform files in a Broccoli tree. Unlike ember-cli-preprocess-registry, which is specific to Ember CLI, broccoli-persistent-filter is a more general-purpose tool for creating file transformations in Broccoli.
ember-cli-htmlbars
ember-cli-htmlbars is an Ember CLI plugin that provides a preprocessor for compiling Handlebars templates. It is specifically designed for handling Handlebars templates in Ember applications, whereas ember-cli-preprocess-registry provides a more general framework for managing various types of preprocessors.
ember-cli-babel
ember-cli-babel is an Ember CLI plugin that integrates Babel for transpiling JavaScript files. It allows you to use the latest JavaScript features in your Ember applications. While ember-cli-preprocess-registry provides a way to register and manage custom preprocessors, ember-cli-babel focuses specifically on JavaScript transpilation using Babel.
ember-cli-preprocessor-registry
Used by Ember CLI to provide a registry of preprocessors. The main types
used throughout the system are css
, template
, js
.
Addon Usage
You can access both your own addon's and your parent's (whichever item is including you)
registry via the setupPreprocessorRegistry
hook in your addon's index.js
.
Example:
module.exports = {
name: 'special-js-sauce',
setupPreprocessorRegistry(type, registry) {
if (type !== 'parent') { return; }
registry.add('js', {
name: 'special-js-sauce-preprocessor',
toTree() {
}
});
}
}
API
Registry.prototype.add(type: String, plugin: Plugin)
Adds the provided plugin to the registry for the type specified.
Example:
class SpecialSauce {
get name() { return 'special-sauce'; }
toTree(tree) {
}
}
registry.add('js', new SpecialSauce);
Registry.prototype.load(type: String): Plugin[]
Returns an array of all plugins that are registered for a given type.
Registry.prototype.extensionsForType(type: String): string[]
Returns an array of all known extensions for a given type.
Registry.prototype.remove(type: String, plugin: Plugin)
Removes the provided plugin from the specified type listing.
Running Tests
npm install
npm test