lib.shims
- Type:
- Default:
Configure the shims for CommonJS and ESM output.
shims.cjs
Set the fields to true to enable the corresponding shims for CommonJS output.
shims.cjs['import.meta.url']
Whether to inject shims for the import.meta.url in CommonJS output.
- Default:
true
Options:
-
true: when format iscjs, theimport.meta.urlin source code will be replaced with the URL of the current module.For example, given the following source code:
the CJS output will be transformed to:
-
false: theimport.meta.urlwill be left as is, which will cause a runtime error when running the output.
shims.esm
Set the fields to true to enable the corresponding shims for ESM output.
shims.esm.__filename
Whether to inject shims for the global __filename of CommonJS in ESM output.
- Default:
false
Options:
-
true: when format isesm, the__filenamein source code will be replaced with the filename of the current module.For example, given the following source code:
the ESM output will be transformed to:
-
false: the__filenamewill be left as is, which will cause a runtime error when running the output.
shims.esm.__dirname
Whether to inject shims for the global __dirname of CommonJS in ESM output.
- Default:
false
Options:
-
true: when format isesm, the__dirnamein source code will be replaced with the directory name of the current module.For example, given the following source code:
the ESM output will be transformed to:
-
false: the__dirnamewill be left as is, which will cause a runtime error when running the output.
shims.esm.require
Whether to inject shims for the global require of CommonJS in ESM output.
- Default:
false
Options:
-
true: when format isesm, there will be arequirethat is created bycreateRequireat the beginning of the output which can be accessed in source code like the globalrequirelike CommonJS.For example, given the following source code:
the ESM output will be transformed to:
-
false: therequirewill be left as is, which will cause a runtime error when running the output.
