Browse Source

Allow tree-shaking to be disabled

gh-669
Oskar Segersvärd 9 years ago
parent
commit
5677b3697f
  1. 9
      bin/runRollup.js
  2. 4
      src/Bundle.js
  3. 18
      src/Module.js
  4. 1
      src/rollup.js
  5. 2
      test/test.js

9
bin/runRollup.js

@ -82,12 +82,14 @@ var equivalents = {
format: 'format',
globals: 'globals',
id: 'moduleId',
indent: 'indent',
input: 'entry',
intro: 'intro',
name: 'moduleName',
output: 'dest',
outro: 'outro',
sourcemap: 'sourceMap'
sourcemap: 'sourceMap',
treeshake: 'treeshake'
};
function execute ( options, command ) {
@ -113,12 +115,13 @@ function execute ( options, command ) {
options.onwarn = options.onwarn || log;
options.external = external;
options.indent = command.indent !== false;
options.noConflict = command.conflict === false;
delete command.conflict;
// Use any options passed through the CLI as overrides.
Object.keys( equivalents ).forEach( function ( cliOption ) {
if ( command[ cliOption ] ) {
if ( command.hasOwnProperty( cliOption ) ) {
options[ equivalents[ cliOption ] ] = command[ cliOption ];
}
});

4
src/Bundle.js

@ -31,6 +31,8 @@ export default class Bundle {
this.entryId = null;
this.entryModule = null;
this.treeshake = options.treeshake !== false;
this.resolveId = first(
[ id => ~this.external.indexOf( id ) ? false : null ]
.concat( this.plugins.map( plugin => plugin.resolveId ).filter( Boolean ) )
@ -102,7 +104,7 @@ export default class Bundle {
settled = true;
this.modules.forEach( module => {
if ( module.run() ) settled = false;
if ( module.run( this.treeshake ) ) settled = false;
});
}

18
src/Module.js

@ -601,7 +601,23 @@ export default class Module {
return magicString.trim();
}
run () {
/**
* Statically runs the module marking the top-level statements that must be
* included for the module to execute successfully.
*
* @param {boolean} treeshake - if we should tree-shake the module
* @return {boolean} marked - if any new statements were marked for inclusion
*/
run ( treeshake ) {
if ( !treeshake ) {
this.statements.forEach( statement => {
if ( statement.isImportDeclaration ) return;
statement.mark();
});
return false;
}
let marked = false;
this.statements.forEach( statement => {

1
src/rollup.js

@ -26,6 +26,7 @@ const ALLOWED_KEYS = [
'outro',
'plugins',
'sourceMap',
'treeshake',
'useStrict'
];

2
test/test.js

@ -76,7 +76,7 @@ describe( 'rollup', function () {
return rollup.rollup({ entry: 'x', plUgins: [] }).then( function () {
throw new Error( 'Missing expected error' );
}, function ( err ) {
assert.equal( 'Unexpected key \'plUgins\' found, expected one of: banner, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, plugins, sourceMap, useStrict', err.message );
assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: banner, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, plugins, sourceMap, treeshake, useStrict' );
});
});
});

Loading…
Cancel
Save