• Stars
    star
    118
  • Rank 299,923 (Top 6 %)
  • Language
    JavaScript
  • License
    Other
  • Created almost 11 years ago
  • Updated about 2 years ago

Reviews

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

Repository Details

Alias directories for browserify

Remapify NPM Build Status

A Browserify plugin to map whole directories as different directories to browserify. This is useful if you have a common batch of files that you don't want to have to refer to relatively all the time.

If remapify doesn't work for you for any reason, you might want to give aliasify or pathmodify a look.

Table of Contents generated with DocToc

Why

Suppose you've got an app structure that looks like

app
  - views
    - home
      index.js
    - people
      index.js
      _avatar.js
      _description.js
  - models
    person.js
// _avatar.js
  // this gets really old after a while, and is prone to breaking if you change the directory hiearchy.
  var person = require('../../models/person.js')
  // This is much better
  var person = require('models/person.js')

Usage

var browserify = require('browserify')
  , remapify = require('remapify')
  , b = browserify(__dirname)

b.plugin(remapify, [
  {
    src: './client/views/**/*.js' // glob for the files to remap
    , expose: 'views' // this will expose `__dirname + /client/views/home.js` as `views/home.js`
    , cwd: __dirname // defaults to process.cwd()
    , filter: function(alias, dirname, basename) { // customize file names
      return path.join(dirname, basename.replace('foo', 'bar'))
    }
  }
])

b.bundle()

options [{}]

Array of objects. Each object is one remapping.

src

Glob pattern to find the files to remap.

expose

Replace the cwd of each file in src with this value.

cwd (optional)

Specify the 'current working directory' for the glob pattern to start from and for the expose option to replace.

filter (optional)

Alter the file name on the fly. For example, if you wanted to require _avatar.js as require('avatar') you could do:

var path = require('path')
b.plugin(remapify, [
  {
    src: './**/*.js'
    , filter: function(alias, dirname, basename) {
      return path.join(dirname, basename.replace(/^\_(.*)\.js$/, '$1'))
    }
  }
]);

glob options

All options specified by the glob module can be used as well.

events

Remapify will emit events while processing. This is implemented to make testing easier, but… maybe it'll be useful for other things. The events are emitted on the bundle.

b.on('remapify:files', function(file, expandedAliases, pattern){})

Emitted when all files have been found to be remapped.

  • files The files found to alias
  • expandedAliases The list of files and what they will be exposed as as found so far. Includes this file.
  • pattern The glob pattern in use.

Tests

All tests are mocha. You can run them with either npm test or mocha test. For developing, the tests can be run on file change with npm run tdd

Development

  • Git hooks are installed to make sure nothing goes to wacky.
  • TDD with npm run tdd
  • Release with npm run release
  • Testing runs eslint. You can manually run with npm run lint

Changelog

See CHANGELOG.md

More Repositories

1

docker-syncthing

Syncthing as a docker image
Dockerfile
93
star
2

react-element-query

Element queries for react components.
JavaScript
86
star
3

my_sublime_packages

Joey's Sublime Text 2/3 settings
Python
13
star
4

sequelize-stream

Create a stream of Sequelize create, update, and destroy events.
JavaScript
11
star
5

generator-iojs

A basic node module template, that includes handy git hooks, a release script, and auto-changelog generation.
JavaScript
9
star
6

eslint-plugin-no-console-log

An eslint plugin to warn on usage of console.log, unlike the built-in rule, this allows other console methods.
Shell
8
star
7

dotfiles

macOS (mostly linux compatible) dotfiles
Vim Script
7
star
8

tap-simple

Simple tap formatter: does not clutter output with successes and shows a diff of actual vs. expected.
JavaScript
6
star
9

docker-bud-tls

Docker container for bud-tls
Shell
5
star
10

lucene-escape-query

Escape a string for a lucene query. Effectively removes all special characters.
Shell
5
star
11

styleguide-css

CSS Styleguide
HTML
3
star
12

visible-element

Check a DOM element to see if it's user visible.
JavaScript
3
star
13

markdown-to-slides-server

HTML
3
star
14

1pif-to-csv

Converts 1password .1pif files to csv
JavaScript
3
star
15

camping

2
star
16

the-hit-list-migration

Migrate from The Hit List to Things (or maybe another app)
JavaScript
2
star
17

guess-timezone

Make a best guess of the user's timezone. Uses the Intl API if available. Works on the client and the server.
JavaScript
2
star
18

good-bugsnag

JavaScript
2
star
19

webshim-browserify-example

A bare minimum example showing how to integrate the awesome webshim library via browserify
JavaScript
2
star
20

readinglist-pocket-sync

Sync Safari's Reading List to Pocket
JavaScript
2
star
21

wheelhouse-view

Automagic for backbone views
JavaScript
1
star
22

day-of-week

Returns an number 0-6 of the day of the week from a date. Is timezone aware.
Shell
1
star
23

find-business-days-in-range

Given two dates, return the business days between them.
Shell
1
star
24

font-nunito

Use the Nunito Google Font with your css pre-processor.
Shell
1
star
25

ale-flow

Vim Script
1
star
26

itunes_apps

small apps that can be attached to keyboard shortcuts that help with iTunes
1
star
27

pigger

quicky stats monitoring
JavaScript
1
star
28

is-business-day

Pass a date, get back a boolean. Is timezone aware.
Shell
1
star
29

iomhas

Basic photo CMS
1
star
30

still-there

Simple client and server to ping pushover if a heartbeat is missed
JavaScript
1
star
31

wheelhouse-router

A wheelhouse library to marry flatiron's Director with Backbone's router
JavaScript
1
star
32

storybook-addon-smart-knobs

Automatically created knobs for storybook. Forked version add support for withInfo addon.
JavaScript
1
star
33

autocomplete-test

JavaScript
1
star
34

gulp-nsp

https://www.dropbox.com/s/9um2f6xsucc8h40/April_2014.pdf
JavaScript
1
star
35

mental-models

JavaScript
1
star
36

business-day-math

Add or subtract business days from a start date. Is timezone aware.
JavaScript
1
star