Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function(bundle, options) {
let removeDevelopmentCode = options.removeDevelopmentCode;
let main = bundle.bundles[0];
let firstNode = bundle.nodes[0];
let nodeMap = new Map();
for(let node of bundle.nodes) {
nodeMap.set(node.load.name + ".js", node);
}
let getNode = nodeMap.get.bind(nodeMap);
return rollup.rollup({
input: main,
plugins: [
loadFromGraph(getNode, removeDevelopmentCode),
pluginCommonjs({})
]
})
.then(function(bundle){
return bundle.generate({
format:'es',
sourcemap: true
});
})
.then(function(chunk){
let sourceCode = chunk.code;
if(isProcessShim(firstNode)) {
function treeshake(data) {
let getNode = id => data.graph[id];
let mains = uniq(data.mains.concat(data.loader.bundle));
let cwd = process.cwd().substr(1);
if (os.type().toLowerCase() === "windows_nt"){
cwd = process.cwd().substr(3);
}
return rollup.rollup({
entry: mains,
acorn: {
allowReserved: true,
ecmaVersion: 9
},
experimentalPreserveModules: true,
experimentalCodeSplitting: true,
plugins: [
loadFromGraph(getNode, data),
transpile(getNode, data)
],
onwarn: function(){}
}).then(function(bundle){
return bundle.generate({
format:'es',
resolveImports: resolveImports.bind(null, cwd)