1 | [npm]: https://img.shields.io/npm/v/rollup-plugin-partial-inject
|
2 | [npm-url]: https://www.npmjs.com/package/rollup-plugin-partial-inject
|
3 | [size]: https://packagephobia.now.sh/badge?p=rollup-plugin-partial-inject
|
4 | [size-url]: https://packagephobia.now.sh/result?p=rollup-plugin-partial-inject
|
5 |
|
6 | [![npm][npm]][npm-url]
|
7 | [![size][size]][size-url]
|
8 |
|
9 | # rollup-plugin-partial-inject
|
10 |
|
11 | This plugin looks like a wrapper over a [@rollup/plugin-inject](https://github.com/rollup/plugins/tree/master/packages/inject). This allows you to split the package into parts and load them partially.
|
12 |
|
13 | ## Install
|
14 |
|
15 | Using npm:
|
16 |
|
17 | ```console
|
18 | npm install rollup-plugin-partial-inject --save-dev
|
19 | ```
|
20 |
|
21 | or
|
22 |
|
23 | ```console
|
24 | yarn add -D rollup-plugin-partial-inject
|
25 | ```
|
26 |
|
27 | ## Usage
|
28 |
|
29 | ```js
|
30 | // src/custom_functions.js
|
31 | export function foo() {
|
32 | console.log('foo');
|
33 | }
|
34 |
|
35 | export function bar() {
|
36 | console.log('bar');
|
37 | }
|
38 | ```
|
39 |
|
40 | ```js
|
41 | // src/main.js
|
42 | console.log(CF.foo());
|
43 | ```
|
44 |
|
45 | ```js
|
46 | // rollup.config.js
|
47 | import partial from 'rollup-plugin-partial-inject';
|
48 |
|
49 | export default {
|
50 | input: 'src/main.js',
|
51 | output: {
|
52 | dir: 'output',
|
53 | format: 'cjs',
|
54 | },
|
55 | plugins: [
|
56 | // ...
|
57 | partial({
|
58 | prefix: 'CF.', // custom prefix. '_.' - by default
|
59 | plugin: '', // - if package from node_modules
|
60 | path: './src/custom_functions.js', // - additional path
|
61 | }),
|
62 | // ...
|
63 | ],
|
64 | };
|
65 | ```
|
66 |
|
67 | ### Result:
|
68 |
|
69 | Only one function will be included in the final file.
|
70 |
|
71 | ```js
|
72 | // public/bundle.js
|
73 | (function () {
|
74 | 'use strict';
|
75 | function foo() {
|
76 | console.log('foo');
|
77 | }
|
78 | console.log(foo());
|
79 | })();
|
80 | ```
|
81 |
|
82 | ## Examples:
|
83 |
|
84 | ### Quickly add a [lodash-es](https://www.npmjs.com/package/lodash-es):
|
85 |
|
86 | !The standard package lodash will not work!
|
87 |
|
88 | ```console
|
89 | npm i lodash-es
|
90 | ```
|
91 |
|
92 | ```js
|
93 | // rollup.config.js
|
94 | import partial from 'rollup-plugin-partial-inject';
|
95 |
|
96 | export default {
|
97 | // ...
|
98 | plugins: [
|
99 | // ...
|
100 | partial({ prefix: '_.', plugin: 'lodash-es' }),
|
101 | // ...
|
102 | ],
|
103 | // ...
|
104 | };
|
105 | ```
|
106 |
|
107 | ### Quickly add a [underscore](https://www.npmjs.com/package/underscore):
|
108 |
|
109 | ```js
|
110 | // rollup.config.js
|
111 | // ...
|
112 | partial({ prefix: '_.', plugin: 'underscore', path: 'modules' });
|
113 | // ...
|
114 | ```
|
115 |
|
116 | ### Quickly add a [locutus](https://www.npmjs.com/package/locutus):
|
117 |
|
118 | ```js
|
119 | // rollup.config.js
|
120 | // ...
|
121 | partial({ prefix: 'L.', plugin: 'locutus/php' });
|
122 | // ...
|
123 | ```
|
124 |
|
125 | ### Quickly add a [rxjs](https://www.npmjs.com/package/rxjs):
|
126 |
|
127 | ```js
|
128 | // rollup.config.js
|
129 | // ...
|
130 | partial({ prefix: 'RX.', plugin: 'rxjs' });
|
131 | // ...
|
132 | ```
|
133 |
|
134 | ## Meta
|
135 |
|
136 | [LICENSE (MIT)](/LICENSE)
|