Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/albinotonnina/parcel-plugin-wrapper
Parcel plugin that wraps output files with custom text or code
https://github.com/albinotonnina/parcel-plugin-wrapper
Last synced: 12 days ago
JSON representation
Parcel plugin that wraps output files with custom text or code
- Host: GitHub
- URL: https://github.com/albinotonnina/parcel-plugin-wrapper
- Owner: albinotonnina
- Created: 2018-06-20T13:20:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T17:55:40.000Z (almost 2 years ago)
- Last Synced: 2024-10-14T07:49:53.773Z (26 days ago)
- Language: JavaScript
- Size: 1.45 MB
- Stars: 8
- Watchers: 3
- Forks: 4
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-parcel - Wrapper - Plugin that wraps output files with custom text or code. (Plugins / Other)
README
# parcel-plugin-wrapper
[![Build Status](https://travis-ci.org/albinotonnina/parcel-plugin-wrapper.svg?branch=master)](https://travis-ci.org/albinotonnina/parcel-plugin-wrapper)
[![codecov](https://codecov.io/gh/albinotonnina/parcel-plugin-wrapper/branch/master/graph/badge.svg)](https://codecov.io/gh/albinotonnina/parcel-plugin-wrapper)## Q:What is this thing solving?
Tiny Parcel plugin that wraps output files with custom text or code.
This plugins imitates pretty much what [wrapper-webpack-plugin](https://github.com/levp/wrapper-webpack-plugin) does.
## Install
```
yarn add parcel-plugin-wrapper --dev
```## Usage
Create a `.assetWrapper.js` file in the root folder of your project.
#### Example 1, add some data coming from package.json:
```javascript
const path = require('path')const CWD = process.cwd()
const PACKAGE = require(path.join(CWD, 'package.json'))const yourAssetProcess = async ({name, bundler}) => {
// name = app.ere76r5e76r5e76r.js
if (name.split('.').pop() === 'js' && bundler.options.production) {
return {
header: `/* ${PACKAGE.name} - ${PACKAGE.version} */`,
footer: `// The End.`
}
}
}module.exports = yourAssetProcess
```#### Will output:
```javascript
/* your-project - 3.4.56 */
parcelRequire=function(e,r,n,t){var i="function"==typeof parcelRequire.etc.etc.etc...
[...bla]
[...bla]
[...bla]
// The End
```#### Example 2, Wraps bundle files with '.js' extension in a self invoking function and enables strict mode:
```javascript
const path = require('path')const yourAssetProcess = ({name, bundler}) => {
if (name.split('.').pop() === 'js' && bundler.options.production) {
return {
header: '(function () { "use strict";\n',
footer: '\n})();'
}
}
}module.exports = yourAssetProcess
```## Maintainers
[@albinotonnina](https://github.com/albinotonnina)
## Contribute
PRs accepted.
## License
MIT © 2018 Albino Tonnina