diff --git a/cli/core/package.json b/cli/core/package.json index d7300c47..351bef07 100644 --- a/cli/core/package.json +++ b/cli/core/package.json @@ -18,7 +18,7 @@ "bin": { "repodog": "./bin/repodog.mjs" }, - "main": "./dist/main/index.mjs", + "main": "./dist/esm/index.mjs", "types": "./dist/types/index.d.ts", "publishConfig": { "access": "public" diff --git a/cli/cut/package.json b/cli/cut/package.json index f0b7c953..02e4bbcc 100644 --- a/cli/cut/package.json +++ b/cli/cut/package.json @@ -12,7 +12,7 @@ }, "bugs": "https://github.com/badbatch/repodog/issues", "type": "module", - "main": "./dist/main/index.mjs", + "main": "./dist/esm/index.mjs", "types": "./dist/types/index.d.ts", "publishConfig": { "access": "public" diff --git a/cli/new/_templates/pkg/library/package.ejs.t b/cli/new/_templates/pkg/library/package.ejs.t index 2e23edd2..d0232764 100644 --- a/cli/new/_templates/pkg/library/package.ejs.t +++ b/cli/new/_templates/pkg/library/package.ejs.t @@ -16,7 +16,7 @@ sh: "<%= packageManager %> install" }, "bugs": "<%= homepage %>/issues", "type": "module", - "main": "./dist/main/index.mjs", + "main": "./dist/esm/index.mjs", "types": "./dist/types/index.d.ts", "publishConfig": { "access": "public" diff --git a/cli/new/_templates/repo/library/package.ejs.t b/cli/new/_templates/repo/library/package.ejs.t index 7c20918b..4dd3abd8 100644 --- a/cli/new/_templates/repo/library/package.ejs.t +++ b/cli/new/_templates/repo/library/package.ejs.t @@ -15,7 +15,7 @@ sh: "<%= packageManager %> install && <%= packageManager %> add -D @repodog/cli }, "bugs": "<%= homepage %>/issues", "type": "module", - "main": "./dist/main/index.mjs", + "main": "./dist/esm/index.mjs", "types": "./dist/types/index.d.ts", "publishConfig": { "access": "public" diff --git a/cli/new/package.json b/cli/new/package.json index e7cc751a..4a7ee823 100644 --- a/cli/new/package.json +++ b/cli/new/package.json @@ -12,7 +12,7 @@ }, "bugs": "https://github.com/badbatch/repodog/issues", "type": "module", - "main": "./dist/main/index.mjs", + "main": "./dist/esm/index.mjs", "types": "./dist/types/index.d.ts", "publishConfig": { "access": "public" diff --git a/cli/postinstall/package.json b/cli/postinstall/package.json index 465c1bd0..471369aa 100644 --- a/cli/postinstall/package.json +++ b/cli/postinstall/package.json @@ -12,7 +12,7 @@ }, "bugs": "https://github.com/badbatch/repodog/issues", "type": "module", - "main": "./dist/main/index.mjs", + "main": "./dist/esm/index.mjs", "types": "./dist/types/index.d.ts", "publishConfig": { "access": "public" diff --git a/cli/publish/package.json b/cli/publish/package.json index 73b47bad..cd0e6559 100644 --- a/cli/publish/package.json +++ b/cli/publish/package.json @@ -12,7 +12,7 @@ }, "bugs": "https://github.com/badbatch/repodog/issues", "type": "module", - "main": "./dist/main/index.mjs", + "main": "./dist/esm/index.mjs", "types": "./dist/types/index.d.ts", "publishConfig": { "access": "public" diff --git a/cli/setup/package.json b/cli/setup/package.json index 3d3b222e..2544a6b1 100644 --- a/cli/setup/package.json +++ b/cli/setup/package.json @@ -12,7 +12,7 @@ }, "bugs": "https://github.com/badbatch/repodog/issues", "type": "module", - "main": "./dist/main/index.mjs", + "main": "./dist/esm/index.mjs", "types": "./dist/types/index.d.ts", "publishConfig": { "access": "public" diff --git a/cli/utils/package.json b/cli/utils/package.json index 33bba01a..1564ddea 100644 --- a/cli/utils/package.json +++ b/cli/utils/package.json @@ -12,7 +12,7 @@ }, "bugs": "https://github.com/badbatch/repodog/issues", "type": "module", - "main": "./dist/main/index.mjs", + "main": "./dist/esm/index.mjs", "types": "./dist/types/index.d.ts", "publishConfig": { "access": "public" diff --git a/cli/write/package.json b/cli/write/package.json index 9198f57a..1ee4a3f0 100644 --- a/cli/write/package.json +++ b/cli/write/package.json @@ -12,7 +12,7 @@ }, "bugs": "https://github.com/badbatch/repodog/issues", "type": "module", - "main": "./dist/main/index.mjs", + "main": "./dist/esm/index.mjs", "types": "./dist/types/index.d.ts", "publishConfig": { "access": "public" diff --git a/configs/rollup-config/README.md b/configs/rollup-config/README.md index b7cfaaae..c5ee99b5 100644 --- a/configs/rollup-config/README.md +++ b/configs/rollup-config/README.md @@ -43,6 +43,10 @@ module.exports = { ### Environment variables +`MODULE_SYSTEM` = `'esm' || 'cjs'` + +Sets `output.format`, directory name within `./dist` output, and the extension of the bundled output file. Default `'esm'`. + `NODE_ENV` = `'prod' || 'production' || 'dev' || 'development'` When set to `'prod'` or `'production'`, terser mangles and compresses, the bundle analyser runs, and source maps are omitted. diff --git a/configs/rollup-config/index.cjs b/configs/rollup-config/index.cjs index 62a2e249..691de554 100644 --- a/configs/rollup-config/index.cjs +++ b/configs/rollup-config/index.cjs @@ -10,10 +10,11 @@ const { plugin: analyzer } = require('rollup-plugin-analyzer'); const copy = require('rollup-plugin-copy'); const sourcemaps = require('rollup-plugin-sourcemaps'); -const { NODE_ENV } = process.env; +const { MODULE_SYSTEM = 'esm', NODE_ENV } = process.env; const isProdEnv = NODE_ENV === 'production' || NODE_ENV === 'prod'; const packageDir = process.cwd(); const external = id => !id.startsWith('.') && !id.startsWith('/'); +const outputExtension = MODULE_SYSTEM === 'esm' ? 'mjs' : 'cjs'; const sourcemapPathTransform = sourcePath => { if (/node_modules/.test(sourcePath)) { @@ -72,8 +73,8 @@ module.exports = (config = {}) => { } }, output: { - file: `${packageDir}/dist/main/index.mjs`, - format: 'esm', + file: `${packageDir}/dist/${MODULE_SYSTEM}/index.${outputExtension}`, + format: MODULE_SYSTEM, sourcemap: true, sourcemapPathTransform, }, diff --git a/package.json b/package.json index 65c36746..b08bd068 100644 --- a/package.json +++ b/package.json @@ -93,4 +93,4 @@ "syncpack": "^9.8.6", "typescript": "^5.0.3" } -} \ No newline at end of file +}