@godown/cli
v0.2.0
Published
A CLI for building package
Readme
@godown/cli
A low-configuration bundler powered by Rollup + OXC or Rolldown.
By default, it treats the dependencies and peerDependencies in the package.json as external dependencies, applies TypeScript transformation options from tsconfig.json, and respects its rootDir, outDir, includes, and excludes when generating outputs.
npm i -D @godown/cli rollup # if using Rollup
npm i -D @godown/cli rolldown # if using Rolldown
npm i -g @godown/cli # if using the CLI globallyCLI
build
pnpm godown build
pnpm godown build -d dist/module -d dist/node --format cjs --map --dts --tsconfig tsconfig.json --minifyWhen using multiple -d flags, please add the -f flag promptly, as they are end-aligned.
# Incorrect (may cause unexpected output):
pnpm godown build -d dist/node --format cjs -d dist/module
# ^^^^^^^^^ └──────^^^^^^^^^^^
# no format match cjs
# Correct:
pnpm godown build -d dist/node --format cjs -d dist/module --format esm
# ^^^^^^^^^────────────┘ ^^^^^^^^^^^────────────┘
# cjs esmYou can pass --bundler to specify the bundler.
pnpm godown build --bundler rollup
pnpm godown build --bundler rolldownPass the repeatable --globals option to specify globals.
Key-value pairs can be separated using either = or :.
Pass the repeatable --external option to specify external IDs.
If the globals options is provided, external defaults to the keys of globals;
otherwise, it defaults to the keys of dependencies and peerDependencies in package.json.
To remove externals, pass a non-existent id.
compile
The compile command compiles only TypeScript to JavaScript.
# automatically detects tsconfig.json
pnpm godown compile
# compile signal file
pnpm godown compile some-ts-file.ts -o some-js-file.js
# compile multiple files
pnpm godown compile src-dir -o out-dir --dts --mapmanifest
The manifest command will generate web components manifests
Infer the framework from the dependencies, peerDependencies in package.json.
pnpm godown manifestThis command will generate:
custom-elements.jsonvscode.css-custom-data.jsonvscode.html-custom-data.jsonweb-types.json
help
Run godown help, godown help [command] to display help.
Runtime Config
Set the runtime configuration using a JSON or JSONC format.
{
"build": {
"bundler": "rollup",
"minify": false,
"map": true,
"dts": true,
"name": "MyLibrary",
"globals": {
"deps": "Deps"
},
"outputs": {
"./src/tests/*": null,
"./src/*.ts": {
"esm": "./build/*.js",
"cjs": "./build/*.cjs"
},
"./build/index.js": {
"umd": "./build/bundle.js"
}
}
},
"manifest": false,
"tsconfig": "tsconfig.json"
}pnpm godown build -c path_to_json_fileBuild outputs
Use formatting as the key and the output location as the value.
Use * as a wildcard for file names to match multiple path levels.
An output ending with / is treated as a directory
The portion before the * is treated as the directory path, while the * itself serves as a file name wildcard placeholder.
Otherwise, it's treated as single-file output, in this case the input must also be a single file.
In this example, the build command will:
Ignore
./src/tests/*, because it's vale isnull.Bundle
./src/*.tsto./build/*.jswith ESM format and./build/*.cjswith CJS format.Bundle
./build/index.jsto./build/bundle.jswith UMD format after./src/*.tsis bundled.
Plugins
The list of built-in plugins is as follows:
For manifest:
- cem-plugin-define
- custom-element-jet-brains-integration
- custom-element-vs-code-integration
For build:
- @rollup/plugin-commonjs
- @web/rollup-plugin-html
- rollup-plugin-minify-html-parts
- rollup-plugin-oxc
- rollup-plugin-template-replace
Postcss:
- autoprefixer
- postcss-csso
