https://github.com/miguelcastillo/bit-loader-shimmer
plugin for shimming modules in bit-bundler
https://github.com/miguelcastillo/bit-loader-shimmer
Last synced: about 1 month ago
JSON representation
plugin for shimming modules in bit-bundler
- Host: GitHub
- URL: https://github.com/miguelcastillo/bit-loader-shimmer
- Owner: MiguelCastillo
- License: mit
- Created: 2016-07-24T14:34:56.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-05-23T12:09:39.000Z (almost 5 years ago)
- Last Synced: 2025-03-16T07:07:09.213Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 46.9 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bit-loader-shimmer
[](https://greenkeeper.io/)
plugin for shimming modules in bit-bundler.
# Install
`$ npm install @bit/loader-shimmer`
# Options
## path
String for defining the path where the file is located.
``` javascript
shim({
boostrap: {
path: './node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
}
})
```## name
As an alternative to path, you can specify module names which go through the same process of module name resolution as any other module.
``` javascript
shim({
boostrap: {
name: 'bootstrap-sass/assets/javascripts/bootstrap',
}
})
```## imports
Configuration for defining dependencies. You can provide a module name, an array of them, or configuration objects for richer definitions. With objects you can define import aliases as well as globals.
> When defining a configuration object with a module name as well as a global name, the module name is imported and also written to the global object.
The following example does a few things.
1. Defines the specific file to be used when the module `bootstrap` is imported by another module.
2. It defines a dependency on `jquery`, which causes `jquery` to be laoded first and brought in as a dependency.
3. It creates a local variable called `jQuery` which points to `jquery`.``` javascript
shim({
boostrap: {
path: './node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
imports: [{
as: 'jQuery',
name: 'jquery'
}]
}
})// The result is something like:
// jQuery = require('jquery');
```You can also just import something from the global object.
``` javascript
shim({
boostrap: {
path: './node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
imports: [{
as: 'jQuery',
global: '$'
}]
}
})// The result is something like:
// jQuery = global['$'];
```This following example expands on the previous examples by writing `jquery` to the global object with names `$` and `jQuery`.
``` javascript
shim({
boostrap: {
path: './node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
imports: [{
as: 'jQuery',
global: ['$', 'jQuery'],
name: 'jquery'
}]
}
})// The result is something like:
// jQuery = global['$'] = global['jQuery'] = require('jquery');
```## exports
Configuration for exporting globals and local variables as modules for other modules to import. You can provide a module name, a configuration object, or array of configuration objects for richer definitions. When defining objects, you can specify export aliases as well as global names to export.
> When defining a configuration object with a local variable name as well as a global name, the variable name is also written to the global object.
In the following example, `bootstrap` exports the local variable `jQuery.Modal` as a module with the name `Modal`. Consequently, modules will be able to import `Modal`.
``` javascript
shim({
boostrap: {
path: './node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
imports: [{
as: 'jQuery',
name: 'jquery'
}]
exports: [{
as: 'Modal',
name: 'jQuery.Modal'
}]
}
})// The result for the export is something like:
// module.exports['Modal'] = jQuery.Modal;
```The following example is a tweak to the previous example where `bootstrap` exports `jQuery.Modal` from the global object as a module with the name `Modal`.
``` javascript
shim({
boostrap: {
path: './node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
imports: [{
name: 'jquery',
as: 'jQuery'
}]
exports: [{
as: 'Modal',
global: 'jQuery.Modal'
}]
}
})// The result for the export is something like:
// module.exports['Modal'] = global['jQuery.Modal'];
```The following example exports `Modal` and writes to the global object.
``` javascript
shim({
boostrap: {
path: './node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
imports: [{
name: 'jquery',
as: 'jQuery'
}]
exports: [{
as: 'Modal',
name: 'jQuery.Modal',
global: 'jQuery.Modal'
}]
}
})// The result for the export is something like:
// module.exports['Modal'] = global['jQuery.Modal'] = jQuery.Modal;
```# License
Licensed under MIT