UNPKG

1.25 kBJavaScriptView Raw
1'use strict';
2
3var bpack = require('browser-pack');
4var fs = require('fs');
5var path = require('path');
6var xtend = require('xtend');
7
8var preludePath = path.join(__dirname, 'prelude.js');
9var prelude = fs.readFileSync(preludePath, 'utf8');
10
11// This plugin replaces the prelude and adds a transform
12var plugin = exports.plugin = function (bfy, opts) {
13 function replacePrelude() {
14 var packOpts = {
15 raw : true, // Added in regular Browserifiy as well
16 preludePath : preludePath,
17 prelude : prelude
18 };
19
20 // browserify sets "hasExports" directly on bfy._bpack
21 bfy._bpack = bpack(xtend(bfy._options, packOpts));;
22 // Replace the 'pack' pipeline step with the new browser-pack instance
23 bfy.pipeline.splice('pack', 1, bfy._bpack);
24 }
25
26 bfy.transform(require('./transform'));
27 bfy.on('reset', replacePrelude);
28
29 replacePrelude();
30};
31
32// Maintain support for the old interface
33exports.browserify = function (files) {
34 console.error('You are setting up proxyquireify via the old API which will be deprecated in future versions.');
35 console.error('It is recommended to use it as a browserify-plugin instead - see the example in the README.');
36 return require('browserify')(files).plugin(plugin);
37};