|
| 1 | +[](https://www.npmjs.com/package/rollup-plugin-external-assets) |
| 2 | +[](https://www.npmjs.com/package/rollup-plugin-external-assets) |
| 3 | +[](https://travis-ci.com/soufyakoub/rollup-plugin-external-assets) |
| 4 | +[][1] |
| 5 | + |
| 6 | +# rollup-plugin-external-assets |
| 7 | +> Make assets external but include them in the output. |
| 8 | +
|
| 9 | +## Installation |
| 10 | + |
| 11 | +Via [npm][2] |
| 12 | + |
| 13 | +```sh |
| 14 | +npm install --save-dev rollup-plugin-external-assets |
| 15 | +``` |
| 16 | + |
| 17 | +Via [yarn][3] |
| 18 | + |
| 19 | +```sh |
| 20 | +yarn add -D rollup-plugin-external-assets |
| 21 | +``` |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +```javascript |
| 26 | +import nodeResolve from "@rollup/plugin-node-resolve"; |
| 27 | +import externalAssets from "rollup-plugin-external-assets"; |
| 28 | + |
| 29 | +export default { |
| 30 | + input: "src/index.js", |
| 31 | + output: { |
| 32 | + file: "dist/index.js", |
| 33 | + format: "es", |
| 34 | + sourcemap: true, |
| 35 | + }, |
| 36 | + plugins: [ |
| 37 | + nodeResolve(), |
| 38 | + externalAssets("assets/*.png"), |
| 39 | + ], |
| 40 | +}; |
| 41 | +``` |
| 42 | + |
| 43 | +## API |
| 44 | + |
| 45 | +```typescript |
| 46 | +function externalAssets( |
| 47 | + pattern: string | RegExp | (string | RegExp)[], |
| 48 | + options: { |
| 49 | + exclude?: string | RegExp | (string | RegExp)[], |
| 50 | + include?: string | RegExp | (string | RegExp)[], |
| 51 | + } |
| 52 | +) |
| 53 | +``` |
| 54 | + |
| 55 | +### pattern |
| 56 | + |
| 57 | +A picomatch pattern, or array of patterns, which correspond to assets the plugin should operate on. |
| 58 | + |
| 59 | +```javascript |
| 60 | +// Process imports that reference images in the <working dir>/assets directory. |
| 61 | +externalAssets("assets/**/*.jpg"); |
| 62 | +// Process imports that reference images in the <working dir>/assets directory, and all stylesheet files. |
| 63 | +externalAssets(["assets/**/*.{jpg,png}", /\.(css|scss)$/]) |
| 64 | +``` |
| 65 | + |
| 66 | +### options |
| 67 | + |
| 68 | +- **include**?: A picomatch pattern, or array of patterns, |
| 69 | +which correspond to modules the plugin should operate on. |
| 70 | +By default all modules are targeted. |
| 71 | + |
| 72 | +- **exclude**?: A picomatch pattern, or array of patterns, |
| 73 | +which correspond to modules the plugin should ignore. |
| 74 | +By default no modules are ignored. |
| 75 | + |
| 76 | +```javascript |
| 77 | +// Don't process imports from js modules in src/exclude. |
| 78 | +externalAssets("assets/**/*", {exclude: "src/exclude/*.js"}); |
| 79 | +// Process imports only from js modules in src/include. |
| 80 | +externalAssets("assets/**/*", {include: "src/include/*.js"}); |
| 81 | +// Process imports from js modules in src/include, but not from js modules in src/exclude. |
| 82 | +externalAssets("assets/**/*", {include: "src/include/*.js", exclude: "src/exclude/*.js"}); |
| 83 | +``` |
| 84 | + |
| 85 | +## Contributing |
| 86 | + |
| 87 | +### Prerequisites |
| 88 | +- [nodejs][4] |
| 89 | +- [npm][2] |
| 90 | + |
| 91 | +### Getting Started |
| 92 | + |
| 93 | +After cloning this repo, ensure dependencies are installed by running: |
| 94 | + |
| 95 | +```sh |
| 96 | +npm install |
| 97 | +``` |
| 98 | + |
| 99 | +Then to build the final bundle: |
| 100 | + |
| 101 | +```sh |
| 102 | +npm run build |
| 103 | +``` |
| 104 | + |
| 105 | +### Tests |
| 106 | + |
| 107 | +To run tests: |
| 108 | + |
| 109 | +```sh |
| 110 | +npm test |
| 111 | +``` |
| 112 | + |
| 113 | +Note that rollup may emit warnings for unspecified options, or for some other reasons. |
| 114 | +I made sure they are ignored with the `no-rollup-warnings` flag in the npm test script. |
| 115 | + |
| 116 | +If you want to see all the warnings when running tests, use this command instead: |
| 117 | + |
| 118 | +```sh |
| 119 | +npm run test:warn |
| 120 | +``` |
| 121 | + |
| 122 | +### Commiting changes |
| 123 | + |
| 124 | +Please follow the [conventional commits][5] specification, because [semantic-release][6] is used to automate the whole package release workflow including: determining the next version number, generating the release notes and publishing the package. |
| 125 | + |
| 126 | +## License |
| 127 | + |
| 128 | +[MIT][1] |
| 129 | + |
| 130 | +[1]: LICENSE |
| 131 | +[2]: https://npmjs.org/ |
| 132 | +[3]: https://yarnpkg.com |
| 133 | +[4]: https://nodejs.org |
| 134 | +[5]: https://www.conventionalcommits.org/en/v1.0.0/ |
| 135 | +[6]: https://github.com/semantic-release/semantic-release |
0 commit comments