@prebuilder/rollup v1.0.3
Install
npm i --save-dev @prebuilder/rollup
Usage
1) Command line:
pb-rollup
rollup
2) Adding Rollup parameters:
rollup -w -c myrollup.config.mjs
pb-rollup -w -c myrollup.config.mjs
Then update the rollup config file of your project, to use prebuilder:
// let prebuilder set the path
let src = process.env.__prebuilderOutput;
export default {
// remove "src"
//input: "src/index.js",
// add prebuilder output like this
input: src + "/index.js",
output: {
file: "dist/index.js",
},
}
module.exports = {
srcDir: 'src',
log: false,
preprocessOptions: {
defines: [
"MY_DIRECTIVE"
],
mode: "both"
}
}
3) Adding Prebuilder parameters:
Put prebuilder parameters in a prebuilder config file (to avoid conflict with rollup's parameters) and set it as follows:
pb-rollup -pbc myPrebuilder.config.js
Differences with @prebuilder/rollup-plugin
The differences between this rollup helper, and @prebuilder/rollup-plugin
are:
| | pb-rollup | rollup-plugin |
| --- | :---: | :---: |
| faster processing | ❌manages files +processes them | ✔ processes files |
| Not affected by configurationedge cases | ✔ | ❌can become unusable for complex rollup configs, depending on what other plugin is used ¹ |
¹ If, for example, using the typsescript rollup plugin which seems to manage .ts files on non-transform hooks, this wrapper is then more suitable.
How it works
- Lets Prebuilder control when and how to run rollup.
- Checks if watch mode is enabled for Rollup, and applies it to Prebuilder.
- Makes Prebuilder watch the source, and Rollup watch the output of Prebuilder (when in watch mode).
Current limitations
The scripts in source folder must not import from outside it using a relative path (
../
), meaning:import ** from "react" // ✔ an npm package path = require(path) // ✔ a node.js library import path from "path" import ** from "/folder/script.js" // ✔ from an absolute path import ** from "C:/folder/script.js" import ** from "https://site.net/script.js" // ✔ from an url import ** from "./script.js" // ✔ from relative path inside src folder import ** from "../../../script.js" // ❌ from relative path outside src folder