First off I don't even know if rollup is the tool i should be using or not.
I have a few TS files which are compiled into JS. I now want to avoid having to refer to run my code in Chrome browser. I don't care if my code runs in node.js or not.
If my assumption is correct then this is how i proceeded:
rollup test_entry.js --file bundle.js --format iife<script src='bundle.js'></script>Object.defineProperty(exports, "__esModule", { value: true });Your approach looks sound to me. I am a little puzzled that your code contains the line Object.defineProperty(exports, "__esModule", { value: true }) as this line should only be added for formats cjs, umd and amd.
Is this line added by rollup or is it already part of your code? Are you using rollup-plugin-typescript? Otherwise you should make sure that the TypeScript is compiled to ES6 modules, not CommonJS (compilerOptions.module = 'ES6') unless you want to add rollup-plugin-commonjs as well.
Lukas thanks very much for weighing on this
I went back and changed the target in typescript.json to ES2015 from CommonJS.
I also changed the format on rollup command line to "umd"
The result is now runnable with no issues in Chrome.
Just wanted to add that the simplicity of "rollup" usage is amazing!
Closing this
Hi I am facing the same issue. In tsconfig target is ES2015, module is commonjs.For rollup format is set to "umd". But still In the generated JS is see Object.defineProperty(exports, "__esModule", { value: true });.
Could you provide me the right combination of target, module and format so that I don't get the exports option in generated module.
I am using gulp-rollup in the below format:
.pipe(rollup({
format: "umd",
moduleName: "Bundle",
entry: PATHS.bundleJSMainFile
}))
Most helpful comment
Hi I am facing the same issue. In tsconfig target is ES2015, module is commonjs.For rollup format is set to "umd". But still In the generated JS is see
Object.defineProperty(exports, "__esModule", { value: true });.Could you provide me the right combination of target, module and format so that I don't get the exports option in generated module.
I am using gulp-rollup in the below format:
.pipe(rollup({ format: "umd", moduleName: "Bundle", entry: PATHS.bundleJSMainFile }))