0.1.7 • Published 12 months ago
@toolbuilder/rollup-plugin-create-pack-file v0.1.7
Rollup-Plugin-Create-Pack-File
This Rollup plugin creates a pack file from your package, and moves it somewhere else as part of testing your package.
This plugin is used by @toolbuilder/rollup-plugin-test-tools, which tests your pack file in temporary ES, CommonJS, and Electron projects.
Installation
npm install --save-dev @toolbuilder/rollup-plugin-create-pack-fileUse
import createPackFile from '@toolbuilder/rollup-plugin-create-pack-file'
export default {
input: 'entry-point.js',
output: {
// By default the plugin will use output.dir or dirname(output.file) for the output directory
file: 'somewhere/es/entry-point.js'
format: 'es'
},
plugins: [
createPackFile({
// if you want the packfile in another place than dirname(output.file) or output.dir,
// specify that directory here.
outputDir: 'somewhere'
})
]
}This plugin runs using the generateBundle hook. This lets you use the pack file when the writeBundle hook runs. The writeBundle hook runs plugins in parallel, so you can't control plugin execution order.
Options
There are a number of options. The advanced options exist for unit testing, but you might find them useful.
Basic Options:
rootDir- tell the plugin where the package root is located. By default, this isprocess.cwd().outputDir- tell the plugin the output directory for the pack file. By default the plugin uses Rollup optionsoutput.dirordirname(output.file)- whichever was specified.packCommand- tell the plugin what command to use to generate the pack file. This is not run in a shell, butexecais used to parse the command. By default, this isnpm pack. For example, I use pnpm instead ofnpm, so my packCommand option looks likepnpm pack. The plugin expects the pack file name to matchnpmnaming conventions.
Advanced options:
packageJson- By default, the plugin readspackage.jsonatrootDirto figure out the pack file name. If you want something else, provide this option an Object that hasnameandversionattributes just likepackage.jsondoes.mover- Async method that moves the pack file. Signature looks like this: async (fullPackFilePath, fullTargetPackFilePath) => {}. No return value is expected. AnErrorshould be thrown on failure. By default the plugin provides a function to move the file.shellCommand- An async method that creates the pack file when given thepackCommandoption value. No return value is expected, anErrorshould be thrown on failure. By default, the plugin usesexeca.commandto runpackCommand.
Contributing
Contributions are welcome. Please create a pull request.
I use pnpm instead of npm.
Issues
This project uses Github issues.