├── .babelrc
├── .gitignore
├── .travis.yml
├── LICENSE.txt
├── README.md
├── package.json
├── rollup.config.js
├── src
└── index.js
└── test
├── sample
├── main.js
├── robot.html
├── rollup.config.js
└── test.coffee
└── test.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "ignore": ["node_modules/**/*.js"],
3 | "env": {
4 | "development": {
5 | "presets": ["es2015"]
6 | },
7 | "production": {
8 | "presets": ["es2015-rollup"]
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.log
2 | npm-debug.log*
3 | node_modules
4 | .npm
5 | .node_repl_history
6 | test/sample/bundle.js
7 | dist
8 | yarn.lock
9 | package-lock.json
10 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: node_js
3 | node_js:
4 | - "node"
5 | - "lts/*"
6 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Ville Lautanala
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rollup-plugin-browserify-transform
2 | [](https://travis-ci.org/lautis/rollup-plugin-browserify-transform)
3 |
4 | Use any Browserify transform with Rollup.
5 |
6 | ## Why?
7 |
8 | There isn't an equivalent for every Browserify transform as Rollup plugin.
9 |
10 | ## Installation
11 |
12 | ```bash
13 | npm install --save-dev rollup-plugin-browserify-transform
14 | ```
15 |
16 | ## Usage
17 |
18 | ```js
19 | // rollup.config.js
20 | import browserifyPlugin from 'rollup-plugin-browserify-transform'
21 | import brfs from 'brfs'
22 |
23 | export default {
24 | entry: 'main.coffee',
25 |
26 | plugins: [
27 | browserifyPlugin(brfs)
28 | ]
29 | }
30 | ```
31 |
32 | Browserify transform plugin accepts `options.include` and `options.exclude`
33 | (each a minimatch pattern, or an array of minimatch patterns) to determine which
34 | files are handled by the Browserify transform. By default, all files are
35 | transpiled.
36 |
37 | You can give Browserify transform options through a second argument.
38 |
39 | ```js
40 | // rollup.config.js
41 | import browserifyPlugin from 'rollup-plugin-browserify-transform'
42 | import coffeeify from 'coffeeify'
43 |
44 | export default {
45 | entry: 'main.coffee',
46 |
47 | plugins: [
48 | browserifyPlugin(coffeeify, { bare: true })
49 | ]
50 | }
51 | ```
52 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rollup-plugin-browserify-transform",
3 | "version": "1.0.1",
4 | "description": "Use Browserify transforms with Rollup",
5 | "keywords": [
6 | "rollup-plugin",
7 | "browserify"
8 | ],
9 | "license": "MIT",
10 | "homepage": "https://github.com/lautis/rollup-plugin-browserify-transform",
11 | "author": "Ville Lautanala",
12 | "devDependencies": {
13 | "babel-preset-es2015": "^6.3.13",
14 | "babel-preset-es2015-rollup": "^3.0.0",
15 | "babel-register": "^6.3.13",
16 | "brfs": "^1.0.0",
17 | "coffeeify": "^3.0.1",
18 | "coffeescript": "^2.0.3",
19 | "mocha": "^4.0.1",
20 | "rollup": "^0.52.0",
21 | "rollup-plugin-babel": "^3.0.2"
22 | },
23 | "scripts": {
24 | "build": "rm -rf dist/* && BABEL_ENV=production rollup -c -f cjs -o dist/rollup-plugin-browserify-transform.cjs.js && BABEL_ENV=production rollup -c -f es -o dist/rollup-browserify-transform.es6.js",
25 | "test": "mocha --require babel-register",
26 | "prepare": "npm run build"
27 | },
28 | "dependencies": {
29 | "concat-stream": "^1.5.1",
30 | "object-assign": "^4.0.1",
31 | "rollup-pluginutils": "^2.0.1",
32 | "source-map-url": "^0.4.0"
33 | },
34 | "files": [
35 | "README.md",
36 | "LICENSE.txt",
37 | "dist"
38 | ],
39 | "repository": {
40 | "type": "git",
41 | "url": "git+https://github.com/lautis/rollup-plugin-browserify-transform.git"
42 | },
43 | "bugs": {
44 | "url": "https://github.com/lautis/rollup-plugin-browserify-transform/issues"
45 | },
46 | "main": "dist/rollup-plugin-browserify-transform.cjs.js",
47 | "jsnext:main": "dist/rollup-plugin-browserify-transform.es6.js"
48 | }
49 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import babel from 'rollup-plugin-babel'
2 |
3 | export default {
4 | entry: 'src/index.js',
5 | plugins: [babel()],
6 | external: ['concat-stream', 'object-assign', 'source-map-url', 'rollup-pluginutils']
7 | }
8 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import concat from 'concat-stream'
2 | import assign from 'object-assign'
3 | import sourceMapURL from 'source-map-url'
4 | import { createFilter } from 'rollup-pluginutils'
5 |
6 | function parseSourceMap(code) {
7 | const map = sourceMapURL.getFrom(code)
8 | try {
9 | return JSON.parse(new Buffer(map.split(',', 2)[1], 'base64').toString())
10 | } catch(error) {
11 | return { mappings: '' }
12 | }
13 | }
14 |
15 | function extract(code) {
16 | if (sourceMapURL.existsIn(code)) {
17 | return {
18 | code: sourceMapURL.removeFrom(code),
19 | map: parseSourceMap(code)
20 | }
21 | } else {
22 | return {
23 | code: code,
24 | map: { mappings: '' }
25 | }
26 | }
27 | }
28 |
29 | export default function browserifyTransform(plugin, options = {}) {
30 | const browserifyOptions = assign({ _flags: { debug: true } }, options)
31 | const filter = createFilter(browserifyOptions.include, browserifyOptions.exclude)
32 |
33 | return {
34 | transform(code, id) {
35 | if (!filter(id)) return null
36 |
37 | return new Promise(function(resolve, reject) {
38 | const stream = plugin(id, browserifyOptions)
39 | stream.pipe(concat((output) => resolve(extract(output.toString('utf-8')))))
40 | stream.on('error', reject)
41 | stream.write(code)
42 | stream.end()
43 | })
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/test/sample/main.js:
--------------------------------------------------------------------------------
1 | var fs = require('fs');
2 | var html = fs.readFileSync(__dirname + '/robot.html', 'utf8');
3 | console.log(html);
4 |
--------------------------------------------------------------------------------
/test/sample/robot.html:
--------------------------------------------------------------------------------
1 | beep boop
2 |
--------------------------------------------------------------------------------
/test/sample/rollup.config.js:
--------------------------------------------------------------------------------
1 | import browserify from '../../dist/rollup-browserify-transform.es6'
2 | import brfs from 'brfs'
3 |
4 | export default {
5 | entry: 'main.js',
6 | format: 'cjs',
7 | dest: 'bundle.js',
8 | plugins: [browserify(brfs)]
9 | }
10 |
--------------------------------------------------------------------------------
/test/sample/test.coffee:
--------------------------------------------------------------------------------
1 | callback((value) => value + 1)
2 |
--------------------------------------------------------------------------------
/test/test.js:
--------------------------------------------------------------------------------
1 | import assert from 'assert'
2 | import {rollup} from 'rollup'
3 | import browserifyPlugin from '../src'
4 | import brfs from 'brfs'
5 | import coffeeify from 'coffeeify'
6 | import fs from 'fs'
7 |
8 | process.chdir(__dirname)
9 |
10 | describe('rollup-plugin-browserify-transform', () => {
11 | it('transforms code with browserify transform', () => {
12 | const entry = 'sample/main.js'
13 |
14 | return rollup({
15 | input: entry,
16 | plugins: [browserifyPlugin(brfs, {})]
17 | })
18 | .then((bundle) => bundle.generate({ format: 'umd'}))
19 | .then((generated) => assert(generated.code.trim().includes('beep boop')))
20 | })
21 |
22 | it('supports transforms with source maps', () => {
23 | const entry = 'sample/test.coffee'
24 | const source = fs.readFileSync(entry).toString()
25 | return rollup({
26 | input: entry,
27 | plugins: [browserifyPlugin(coffeeify, {})]
28 | })
29 | .then((bundle) => bundle.generate({ format: 'cjs', sourcemap: true }))
30 | .then((generated) => assert.equal(generated.map.sourcesContent[0], source))
31 | })
32 | })
33 |
--------------------------------------------------------------------------------