Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions server/child-processes/create-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,18 @@ function bundle ( cwd, deep, query ) {

const code = sander.readFileSync( entry, { encoding: 'utf-8' });

let external = [];

if (typeof query.externals === 'string') {
external = query.externals.split(',');
}

if ( isModule( code ) ) {
info( `[${pkg.name}] ES2015 module found, using Rollup` );
return bundleWithRollup( cwd, pkg, entry, moduleName );
return bundleWithRollup( cwd, pkg, entry, moduleName, external );
} else {
info( `[${pkg.name}] No ES2015 module found, using Browserify` );
return bundleWithBrowserify( pkg, entry, moduleName );
return bundleWithBrowserify( pkg, entry, moduleName, external );
}
}

Expand All @@ -149,12 +155,13 @@ function findEntry ( file ) {
}
}

async function bundleWithRollup ( cwd, pkg, moduleEntry, moduleName ) {
async function bundleWithRollup ( cwd, pkg, moduleEntry, moduleName, external ) {
const bundle = await rollup.rollup({
entry: path.resolve( cwd, moduleEntry ),
plugins: [
resolve({ module: true, jsnext: true, main: false, modulesOnly: true })
]
],
external,
});

info( `[${pkg.name}] bundled using Rollup` );
Expand All @@ -181,9 +188,10 @@ async function bundleWithRollup ( cwd, pkg, moduleEntry, moduleName ) {
}
}

function bundleWithBrowserify ( pkg, main, moduleName ) {
function bundleWithBrowserify ( pkg, main, moduleName, external ) {
const b = browserify( main, {
standalone: moduleName
standalone: moduleName,
external
});

return new Promise( ( fulfil, reject ) => {
Expand Down