rollup-plugin-partial-inject
v1.0.2
Published
Plugin for quick partial addition of functions from modules
Downloads
27
Maintainers
Readme
rollup-plugin-partial-inject
This plugin looks like a wrapper over a @rollup/plugin-inject. This allows you to split the package into parts and load them partially.
Install
Using npm:
npm install rollup-plugin-partial-inject --save-dev
or
yarn add -D rollup-plugin-partial-inject
Usage
// src/custom_functions.js
export function foo() {
console.log('foo');
}
export function bar() {
console.log('bar');
}
// src/main.js
console.log(CF.foo());
// rollup.config.js
import partial from 'rollup-plugin-partial-inject';
export default {
input: 'src/main.js',
output: {
format: 'iife',
file: 'public/bundle.js',
},
plugins: [
// ...
partial({
prefix: 'CF.', // custom prefix. '_.' - by default
plugin: '', // - if package from node_modules
path: './src/custom_functions.js', // - additional path
}),
// ...
],
};
Result:
Only one function will be included in the final file.
// public/bundle.js
(function () {
'use strict';
function foo() {
console.log('foo');
}
console.log(foo());
})();
Examples:
Quickly add a lodash-es:
The standard package lodash will not work!
npm i lodash-es
// rollup.config.js
import partial from 'rollup-plugin-partial-inject';
export default {
// ...
plugins: [
// ...
partial({ prefix: '_.', plugin: 'lodash-es' }),
// ...
],
// ...
};
Quickly add a underscore:
// rollup.config.js
// ...
partial({ prefix: '_.', plugin: 'underscore', path: 'modules' });
// ...
Quickly add a locutus:
// rollup.config.js
// ...
partial({ prefix: 'L.', plugin: 'locutus/php' });
// ...
Quickly add a rxjs:
// rollup.config.js
// ...
partial({ prefix: 'RX.', plugin: 'rxjs' });
// ...