Closed dmnsgn closed 3 months ago
The shim to be inserted in the right place with a simple config:
const resolve = require('@rollup/plugin-node-resolve'); const commonjs = require('@rollup/plugin-commonjs'); const esmShim = require('@rollup/plugin-esm-shim'); module.exports = { input: 'src/main.js', output: { file: 'dist/main.js', format: 'es', }, plugins: [resolve(), commonjs(), esmShim()], };
from a simple source:
const dn = __dirname; module.exports = { keyword: ' import', dn: '', };
The shims get inserted in the middle of the common js helper.
function getDefa // -- Shims -- import cjsUrl from 'node:url'; import cjsPath from 'node:path'; import cjsModule from 'node:module'; const __filename = cjsUrl.fileURLToPath(import.meta.url); const __dirname = cjsPath.dirname(__filename); const require = cjsModule.createRequire(import.meta.url); ultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } __dirname; var main = { keyword: ' import', dn: '', }; var main$1 = /*@__PURE__*/getDefaultExportFromCjs(main); export { main$1 as default };
Still happening in: "rollup": "^4.9.6" with Node.js v21.6.1
Expected Behavior
The shim to be inserted in the right place with a simple config:
from a simple source:
Actual Behavior
The shims get inserted in the middle of the common js helper.
Additional Information