Git Product home page Git Product logo

requirejs-prune-bundle-output's Introduction

requirejs-prune-bundle-output

NPM version devDependency Status

Deletes all files from the RequireJS bundle output directory, which do not start with the bundle name (<bundle>.js and <bundle>.js.map).

Table of Contents

Synopsis

  // Delete minified file copies that were concatenated to the bundle.
  onModuleBundleComplete: function (data) {
    const pruneBundleOutput = nodeRequire('requirejs-prune-bundle-output')
    pruneBundleOutput('../output', data.name)
  },

Installation

This module can be installed in your project using NPM or Yarn. Make sure, that you use Node.js version 6 or newer.

npm i -D requirejs-prune-bundle-output
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:

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:

  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:

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:

  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:

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.

requirejs-prune-bundle-output's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.