rollup-plugin-string-import 1.0.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -94,6 +94,24 @@ Default: `undefined`
|
|
94
94
|
|
95
95
|
A [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored.
|
96
96
|
|
97
|
+
### `transform`
|
98
|
+
|
99
|
+
Type: `(content: String, file: String) => String`<br>
|
100
|
+
Default: `content => content`
|
101
|
+
|
102
|
+
A transformer function that will be applied to each matched file. In this example, we append "Hello World" to each `.txt` file:
|
103
|
+
|
104
|
+
```typescript
|
105
|
+
...
|
106
|
+
importAsString({
|
107
|
+
include: ['**/*.txt', '**/*.frag', '**/*.vert'],
|
108
|
+
exclude: ['**/*.test.*'],
|
109
|
+
transform:
|
110
|
+
(content, file) => file.endsWith('.txt') ? `${content}\nHello World` : content,
|
111
|
+
}),
|
112
|
+
...
|
113
|
+
```
|
114
|
+
|
97
115
|
## Meta
|
98
116
|
|
99
117
|
Licensed under the GPL version 3.0 or higher
|
package/dist/index.d.ts
CHANGED
@@ -3,6 +3,7 @@ import type { FilterPattern } from '@rollup/pluginutils';
|
|
3
3
|
export type ImportAsStringOptions = {
|
4
4
|
include: FilterPattern;
|
5
5
|
exclude?: FilterPattern;
|
6
|
+
transform?: (content: string, file: string) => string;
|
6
7
|
};
|
7
8
|
export declare function importAsString(options: ImportAsStringOptions): Plugin;
|
8
9
|
export default importAsString;
|
package/dist/index.js
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
import { createFilter } from '@rollup/pluginutils';
|
2
2
|
export function importAsString(options) {
|
3
|
-
const
|
3
|
+
const { include, exclude, transform = content => content } = options;
|
4
|
+
const filter = createFilter(include, exclude);
|
4
5
|
return {
|
5
6
|
name: 'importAsString',
|
6
7
|
transform(code, id) {
|
7
8
|
if (filter(id)) {
|
9
|
+
const content = JSON.stringify(transform(code, id));
|
8
10
|
return {
|
9
|
-
code: `export default ${JSON.stringify(
|
11
|
+
code: `export default ${JSON.stringify(content)};`,
|
10
12
|
map: { mappings: '' },
|
11
13
|
};
|
12
14
|
}
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AASnD,MAAM,UAAU,cAAc,CAAC,OAA8B;IAC3D,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,GAAG,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC;IAErE,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE9C,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,SAAS,CAAC,IAAI,EAAE,EAAE;YAChB,IAAI,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;gBACf,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;gBACpD,OAAO;oBACL,IAAI,EAAE,kBAAkB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG;oBAClD,GAAG,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;iBACtB,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,eAAe,cAAc,CAAC"}
|