11'use strict' ;
22
3- var browserify = require ( 'browserify ' ) ;
3+ var cjs = require ( 'pure-cjs ' ) ;
44var grunt = require ( 'grunt' ) ;
55
66module . exports = function ( ) {
@@ -18,51 +18,26 @@ module.exports = function() {
1818 config . after = [ config . after ] ;
1919 }
2020
21- // create the bundle we'll work with
22- var entries = grunt . file . expand ( config . entries ) ;
23- var bundle = browserify ( entries ) ;
24-
25- // Make sure the things that need to be exposed are.
26- var requires = config . requires || { } ;
27- if ( requires instanceof Array ) {
28- grunt . file . expand ( {
29- nonull : true , // Keep IDs that don't expand to anything.
30- cwd : "src"
31- } , requires ) . forEach ( function ( name ) {
32- bundle . require ( "./build/modules/" + name , {
33- expose : name . replace ( / \. j s $ / i, "" )
34- } ) ;
35- } ) ;
36- } else if ( typeof requires === "object" ) {
37- Object . keys ( requires ) . forEach ( function ( name ) {
38- bundle . require ( requires [ name ] , { expose : name } ) ;
39- } ) ;
40- }
41-
42- // Extract other options
21+ // Extract options
4322 var options = {
44- debug : config . debug , // sourcemaps
45- standalone : config . standalone // global
23+ input : config . entries [ 0 ] ,
24+ output : config . outfile ,
25+ map : config . debug , // sourcemaps
26+ exports : config . standalone , // global
27+ transform : config . transforms ,
28+ dryRun : true // we will write to disk ourselves
4629 } ;
4730
48- // TODO: make sure this works, test with this too
49- config . transforms . forEach ( function ( transform ) {
50- bundle . transform ( { } , transform ) ;
51- } ) ;
52-
5331 // Actually bundle it up
5432 var _this = this ;
55- bundle . bundle ( options , function ( err , src ) {
56- if ( err ) {
57- grunt . log . error ( err ) ;
58- done ( ) ;
59- }
60-
61- config . after . forEach ( function ( fn ) {
62- src = fn . call ( _this , src ) ;
63- } ) ;
33+ cjs . transform ( options ) . then ( function ( result ) {
34+ grunt . file . write ( config . outfile , config . after . reduce ( function ( src , fn ) {
35+ return fn . call ( _this , src ) ;
36+ } , result . code ) ) ;
6437
65- grunt . file . write ( config . outfile , src ) ;
38+ done ( ) ;
39+ } , function ( err ) {
40+ grunt . log . error ( err ) ;
6641 done ( ) ;
6742 } ) ;
6843} ;
0 commit comments