• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A browserify plugin to partition your modules in different bundles

partition-bundle

A browserify plugin to pack multiple related modules together in separate files to make the initial pageload smaller.

npm install partition-bundle

Example

browserify -p [ partition-bundle --map mapping.json --output output/directory --url directory --main ./entry ]

    --map       Path to your configuration file (see below "Configuration file")

    --output    The output directory for your bundles. E.g. if you defined "entry.js" in your
                configuration file and "dist" as the output option, the bundle generated will
                be at "<project>/dist/entry.js".

    --main      Defines which of the configured entry files is the main part of the bundle.
                This will be automatically loaded with the loadjs() function. This has to be
                one of the values in your configuration file; following the example below "./a"
                would a possible choice.

Configuration file

In the mapping/configuration file you can define which module ends up in which output file. Here you can group files together.

{
  "entry.js": ["./a"],
  "common.js": ["./b"],
  "common/extra.js": ["./e", "./d"]
}

The keys of this file (e.g. "common.js") will be the resulting chunk files. The values are arrays to your actual module files.

HINT: Everything an entry file does require() will be put in the resulting bundle. If - like in the above example file - the module ./a does require() module ./b then ./b will be bundled with ./a AND if ./b is also configured as a chunk bundle (see above common.js) the common.js bundle will end up empty.

The modules in this file are automatically required (so no need to extra -r module). Dependencies of those files are grouped into the same destination file.

The first row is the entry file. This file is the file you need to add to your page with a <script src="entry.js"></script>. This also includes necessary boilerplate to load the other files.

Use exposed name

The module could be defined as an object with require and expose properties:

{
  "entry.js": ["./a"],
  "common.js": [{require: "./b.js", expose: "common"}]
}

b.js can be loaded by calling loadjs(['common']).

Loading modules

As some modules are in other files, you obviously need to load them at some point once they are needed. The entry file includes a simple loader which can load the necessary files automatically.

For example in a.js, which is in entry.js you have this:

a.addEventListener('click', function() {
  loadjs(['./e', './d'], function(e, d) {
    console.log(e, d);
  });
});

Once the listener is executed, the common/extra.js file is loaded and the e and d modules become available.

Note: once a module is loaded, the file won't be loaded again, but the result will be cached and returned by other loadjs or require calls, as you are used to with normal modules.

Difference with factor-bundle

factor-bundle is much like this plugin, except that it does not add a loader. It can factor-out common modules in to different output files, but then you need to manually load the files with <script> tags. partition-budle can load the excluded modules later using the loadjs function and by simply using the module ID, rather than the final JS filename.

More Repositories

1

pngjs

Pure JavaScript PNG decoder
JavaScript
171
star
2

CoverJS

Instrument JavaScript to determine the testing coverage
JavaScript
126
star
3

cubic-bezier

A small cubic bΓ©zier timing function
JavaScript
76
star
4

mootools-form-upload

Upload your multiple files with HTML5 Drag and Drop, XMLHttpRequest with graceful degradation
JavaScript
48
star
5

CSSMatrix

CSSMatrix polyfill
JavaScript
44
star
6

Array.Math

Add all kind of mathematical methods to the Array Native
JavaScript
33
star
7

Complex

Calculations with Complex Numbers in JavaScript
JavaScript
26
star
8

amd-packager-php

An CommonJS AMD Packager in PHP
JavaScript
25
star
9

MooDialog

MooDialog is a MooTools plugin to replace the native alert(), confirm() and promt() javascript functions by more stylish ones. You can use it also for other DOM elements, create an IFrame dialog or even create an Ajax Dialog.
JavaScript
23
star
10

LISP.js

Parse and run LISP code in JavaScript
JavaScript
15
star
11

DirectAdminApi

PHP DirectAdminApi is a wrapper for the DirectAdmin Api to make the usage of the Api simple as much as possible
PHP
14
star
12

graphql-kotlin-test-dsl

A Kotlin DSL to write tests for your graphql-java schema
Kotlin
13
star
13

iFrameFormRequest

iFrameFormRequest is a MooTools plug-in that can upload files the Ajax way
JavaScript
13
star
14

Rss-Parser

This is a simple PHP Rss Parser
PHP
12
star
15

classy

Brings the MooTools 1.x Class sugar to Prime
JavaScript
10
star
16

prime-util

Utilities for MooTools Prime
JavaScript
9
star
17

MooDropMenu

MooDropMenu provides a simple Drop Down menu with infinit levels for MooTools
JavaScript
7
star
18

mootools-ui-runner

A Testrunner for MooTools More in PHP
JavaScript
6
star
19

MooDocs

A simple php script to generate MooTools docs, so you can parse the MooTools 1.3 docs for yourself and you're able to help debug the Docs
PHP
5
star
20

G-pack-2.0

The Gourmand Planner, by Andrey Kolobov, Peng Dai, Mausam, and Dan Weld
C++
5
star
21

elements-util

Utilities for elements
JavaScript
5
star
22

scopup

JavaScript scope analysis for Mozilla Parser AST
JavaScript
4
star
23

Element.Delegation

This is a simple MooTools Plugin for Event Delegation, now I would suggest the MooTools More 1.3 Delegation though
JavaScript
4
star
24

MilkyTester

Simultaneous browser tester with Node.js, Socket.io and Jasmine
JavaScript
4
star
25

Supersonic

A small and supersonic flow-controll library for Node.js
JavaScript
3
star
26

docker-android-react-native

docker image for android and react-native tools
Dockerfile
3
star
27

elements-ui

ui components for elements.
JavaScript
3
star
28

Fx.Dynamic

JavaScript
3
star
29

hashmap

Educational hashmap implementation in C.
C
3
star
30

Klass

Yet Another Class
JavaScript
3
star
31

MooDeps

This is a MooTools dependency checker written in MooTools Javascript and PHP
PHP
2
star
32

grunt-wrapup

Grunt Plugin for MooTools Wrapup - Convert your node modules into web modules.
JavaScript
2
star
33

animateImage

AnimateImage is an MooTools plugin to create an animated image
JavaScript
2
star
34

es-safe-ie

Transforms obj.finally into obj['finally'] so it's safe in IE < 9
JavaScript
2
star
35

mootools-docs-node

A MooTools Documentation viewer in Node.js
JavaScript
2
star
36

Drag

Another Drag Implementation
JavaScript
2
star
37

MooResize

MooResize is a MooTools plugin to resize images and other elements in an easy way
JavaScript
2
star
38

go-qoi

QOI decoder and encoder implemented in Go
Go
2
star
39

ptrace

C
2
star
40

Element.Style.Transform

An abstracted API for CSS3 transforms
JavaScript
2
star
41

reactive

Reactive Programming in JavaScript?? (actually, I don't really know exactly what Reactive Programming is)
JavaScript
2
star
42

wrapup-webbuilder

A webbuilder for downloading wrapup'd JavaScript
JavaScript
2
star
43

npm-login-cmd

JavaScript
2
star
44

MooCss

With MooCss (MooTools plugin) you can write Css as Javascript objects (just like Element.Style) to a style tag in the document head
JavaScript
2
star
45

Locale.AutoUse

Automatically determine the right language of the document to use for Locale
JavaScript
1
star
46

dom-binding

DOM data binding, push your objects to the DOM
JavaScript
1
star
47

node-sass-cli

Better CLI for node-sass
JavaScript
1
star
48

wrapup-middleware

Wrapup middleware for express.
JavaScript
1
star
49

metac

A MetaC to C compiler using Spoofax
TypeScript
1
star
50

version.is-sources

Source repo for version-is/version.is
1
star
51

packager-nightly

Download and build from github with packager, can be used with github hooks
PHP
1
star
52

selenium-wrapper

A selenium server wrapper, including installation and chrome webdriver
JavaScript
1
star
53

JAMD

Ported AMD-Packager-PHP to Java! To build and optimize your AMD modules into single files
Java
1
star
54

procs

Stupid Markdown to HTML documentation tool
JavaScript
1
star
55

vim

just showing my vim noobness
Vim Script
1
star
56

node-testbox

Run your tests in a sandboxed iframe
JavaScript
1
star
57

envarconst

Make JavaScript const variable, using esprima to change const declarations in your code, so a minifier like UgilfyJS can remove dead code.
JavaScript
1
star