Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Commit 8595beb

Browse files
committed
wrap modules in a closure, for more readable output
1 parent 6cd13dc commit 8595beb

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ export default function commonjs ( options = {} ) {
114114
sources.map( source => `import ${required[ source ].name} from '${source}';` ).join( '\n' ) :
115115
'';
116116

117-
const intro = `var exports = {}, module = { 'exports': exports };\n`;
118-
const outro = `\nexport default module.exports;`;
117+
const intro = `\n\nexport default (function (module) {\nvar exports = module.exports;\n`;
118+
const outro = `\nreturn module.exports;\n})({exports:{}});`;
119119

120120
magicString.trim()
121121
.prepend( importBlock + intro )
122+
.trim()
122123
.append( outro );
123124

124125
code = magicString.toString();

0 commit comments

Comments
 (0)