Skip to content

Commit

Permalink
feat: add support for cjs builds with rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanaubrey committed Nov 17, 2023
1 parent 71198af commit 8dad12b
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cli/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/cut/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/new/_templates/pkg/library/package.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/new/_templates/repo/library/package.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/new/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/postinstall/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/setup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cli/write/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions configs/rollup-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions configs/rollup-config/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@
"syncpack": "^9.8.6",
"typescript": "^5.0.3"
}
}
}

0 comments on commit 8dad12b

Please sign in to comment.