rollup-plugin-cjs-shim
TypeScript icon, indicating that this package has built-in type declarations

0.0.0 • Public • Published

es module to common js code helper

rollup.config.js

import commonjs from "@rollup/plugin-commonjs";
import cjsShim from "rollup-plugin-cjs-shim";

export default {
  input: "index.js",
  output: {
    file: "index.cjs",
    format: "cjs",
  },
  plugins: [cjsShim(), commonjs()],
};
  • import.meta.filename => __filename
  • import.meta.dirname => __dirname
  • const/var/let require = createRequire(import.meta.url) =>
    • import { createRequire } from "module" =>

example input

import { createRequire } from "module";
export const filename = import.meta.filename;
export const dirname = import.meta.dirname;

const require = createRequire(import.meta.url);

require("./package.json");

output

"use strict";

const filename = __filename;
const dirname = __dirname;

require("./package.json");

exports.dirname = dirname;
exports.filename = filename;

add replacement

import cjsShim, { defaultReplacements } from "rollup-plugin-cjs-shim";

cjsShim({
  replacements: [
    ...defaultReplacements,
    {
      // replacement
    },
  ],
});

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.1
43canary
0.0.05latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.1
43
0.1.0
3
0.0.10
0.0.05

Package Sidebar

Install

npm i rollup-plugin-cjs-shim

Weekly Downloads

51

Version

0.0.0

License

MIT

Unpacked Size

8.31 kB

Total Files

7

Last publish

Collaborators

  • startracex