https://github.com/prantlf/requirejs-prune-bundle-output
Deletes all files from the RequireJS bundle output directory except for the output bundles.
https://github.com/prantlf/requirejs-prune-bundle-output
bundles cleanup prune requirejs
Last synced: 4 months ago
JSON representation
Deletes all files from the RequireJS bundle output directory except for the output bundles.
- Host: GitHub
- URL: https://github.com/prantlf/requirejs-prune-bundle-output
- Owner: prantlf
- License: mit
- Created: 2019-10-27T10:29:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-27T10:29:52.000Z (over 5 years ago)
- Last Synced: 2025-03-09T08:03:33.795Z (4 months ago)
- Topics: bundles, cleanup, prune, requirejs
- Language: JavaScript
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# requirejs-prune-bundle-output
[](http://badge.fury.io/js/requirejs-prune-bundle-output)
[](https://david-dm.org/prantlf/requirejs-prune-bundle-output#info=devDependencies)Deletes all files from the RequireJS bundle output directory, which do not start with the bundle name (`.js` and `.js.map`).
### Table of Contents
- [Synopsis](#synopsis)
- [Installation](#installation-and-getting-started)
- [Documentation](#documentation)
- [Contributing](#contributing)
- [License](#license)## Synopsis
```js
// Delete minified file copies that were concatenated to the bundle.
onModuleBundleComplete: function (data) {
const pruneBundleOutput = nodeRequire('requirejs-prune-bundle-output')
pruneBundleOutput('../output', data.name)
},
```
## InstallationThis module can be installed in your project using [NPM] or [Yarn]. Make sure, that you use [Node.js] version 6 or newer.
```sh
npm i -D requirejs-prune-bundle-output
``````sh
yarn add requirejs-prune-bundle-output
```## Documentation
[RequireJS] copies and minifies all source file to the output directory. However, when module bundles are used, only the bundle is needed to be deployed as the build output.
Let us have the following project structure, where the list of bundled modules is included in each component as `index.js`:
```txt
sources
├── animals
│ ├── animal.js
│ ├── cat.js
│ ├── dog.js
│ ├── counter.js
│ └── index.js
├── loader
│ └── index.js
└── places
├── garden.js
└── index.js
```With the following build configuration:
```js
modules: [
{ name: 'loader/index' },
{ name: 'animals/index', exclude: [ 'loader/index' ] },
{ name: 'places/index', exclude: [ 'loader/index', 'animals/index' ] }
],
dir: '../output'
```When built by `r.js`, the following output will appear in the target directory:
```txt
output
├── loader
│ ├── index.js
│ └── index.js.map
├── animals
│ ├── animal.js
│ ├── cat.js
│ ├── dog.js
│ ├── counter.js
│ ├── index.js
│ └── index.js.map
└── places
├── garden.js
├── index.js
└── index.js.map
```All files except for `index.js*` should be removed before deploying the project output. When calling `pruneBundleOutput` from the bundle completion callback:
```js
modules: [
{ name: 'loader/index' },
{ name: 'animals/index', exclude: [ 'loader/index' ] },
{ name: 'places/index', exclude: [ 'loader/index', 'animals/index' ] }
],
dir: '../output',
onModuleBundleComplete: function (data) {
const pruneBundleOutput = nodeRequire('requirejs-prune-bundle-output')
pruneBundleOutput('../output', data.name)
},
```The extra files will be removed from the directories with the output bundles, leaving only the files to deploy:
```txt
output
├── loader
│ ├── index.js
│ └── index.js.map
├── animals
│ ├── index.js
│ └── index.js.map
└── places
├── index.js
└── index.js.map
```## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
## License
Copyright (c) 2019 Ferdinand Prantl
Licensed under the MIT license.
[Node.js]: http://nodejs.org/
[NPM]: https://www.npmjs.com/
[Yarn]: https://yarnpkg.com/
[RequireJS]: https://requirejs.org/