⚠️ Kdu CLI is in Maintenance Mode!

For new projects, it is now recommended to use create-kdu to scaffold Wite-based projects. Also refer to the Kdu 3 Tooling Guide for the latest recommendations.

CLI Service

Using the Binary

Inside a Kdu CLI project, @kdujs/cli-service installs a binary named kdu-cli-service. You can access the binary directly as kdu-cli-service in npm scripts, or as ./node_modules/.bin/kdu-cli-service from the terminal.

This is what you will see in the package.json of a project using the default preset:

{
  "scripts": {
    "serve": "kdu-cli-service serve",
    "build": "kdu-cli-service build"
  }
}

You can invoke these scripts using either npm or Yarn:

npm run serve
# OR
yarn serve

If you have npx available (should be bundled with an up-to-date version of npm), you can also invoke the binary directly with:

npx kdu-cli-service serve

kdu-cli-service serve

Usage: kdu-cli-service serve [options] [entry]

Options:

  --open         open browser on server start
  --copy         copy url to clipboard on server start
  --mode         specify env mode (default: development)
  --host         specify host (default: 0.0.0.0)
  --port         specify port (default: 8080)
  --https        use https (default: false)
  --public       specify the public network URL for the HMR client
  --skip-plugins comma-separated list of plugin names to skip for this run

--copy

Copying to clipboard might not work on a few platforms. If copying was successful, (copied to clipboard) is displayed next to the local dev server URL.

The kdu-cli-service serve command starts a dev server (based on webpack-dev-server) that comes with Hot-Module-Replacement (HMR) working out of the box.

In addition to the command line flags, you can also configure the dev server using the devServer field in kdu.config.js.

[entry] in the CLI command is defined as the entry file (default: src/main.js or src/main.ts in TypeScript project), not an additional entry file. If you overwrite the entry in the CLI, then the entries from config.pages are no longer considered, which may cause an error.

kdu-cli-service build

Usage: kdu-cli-service build [options] [entry|pattern]

Options:

  --mode         specify env mode (default: production)
  --dest         specify output directory (default: dist)
  --modern       build app targeting modern browsers with auto fallback
  --target       app | lib | wc | wc-async (default: app)
  --formats      list of output formats for library builds (default: commonjs,umd,umd-min)
  --inline-kdu   include the Kdu module in the final bundle of library or web component target
  --name         name for lib or web-component mode (default: "name" in package.json or entry filename)
  --filename     file name for output, only usable for 'lib' target (default: value of --name),
  --no-clean     do not remove the dist directory contents before building the project
  --report       generate report.html to help analyze bundle content
  --report-json  generate report.json to help analyze bundle content
  --skip-plugins comma-separated list of plugin names to skip for this run
  --watch        watch for changes

kdu-cli-service build produces a production-ready bundle in the dist/ directory, with minification for JS/CSS/HTML and auto vendor chunk splitting for better caching. The chunk manifest is inlined into the HTML.

There are a few useful flags:

  • --modern builds your app using Modern Mode, shipping native ES2015 code to modern browsers that support it, with auto fallback to a legacy bundle.

  • --target allows you to build any component(s) inside your project as a library or as web components. See Build Targets for more details.

  • --report and --report-json will generate reports based on your build stats that can help you analyze the size of the modules included in your bundle.

kdu-cli-service inspect

Usage: kdu-cli-service inspect [options] [...paths]

Options:

  --mode    specify env mode (default: development)

You can use kdu-cli-service inspect to inspect the webpack config inside a Kdu CLI project. See Inspecting Webpack Config for more details.

Checking All Available Commands

Some CLI plugins will inject additional commands to kdu-cli-service. For example, @kdujs/cli-plugin-eslint injects the kdu-cli-service lint command. You can see all injected commands by running:

npx kdu-cli-service help

You can also learn about the available options of each command with:

npx kdu-cli-service help [command]

Skipping Plugins

You can exclude specific plugins when running a command by passing the name of the plugin to the --skip-plugins option:

npx kdu-cli-service build --skip-plugins pwa

TIP

This option is available for every kdu-cli-service command, including custom ones added by other plugins.

You can skip multiple plugins by passing their names as a comma-separated list or by repeating the argument:

npx kdu-cli-service build --skip-plugins pwa,apollo --skip-plugins eslint

Plugin names are resolved the same way they are during install, as described here

# these are all equivalent
npx kdu-cli-service build --skip-plugins pwa

npx kdu-cli-service build --skip-plugins @kdujs/pwa

npx kdu-cli-service build --skip-plugins @kdujs/cli-plugin-pwa

Caching and Parallelization

  • cache-loader is enabled for Kdu/Babel/TypeScript compilations by default. Files are cached inside node_modules/.cache - if running into compilation issues, always try deleting the cache directory first.

  • thread-loader will be enabled for Babel/TypeScript transpilation when the machine has more than 1 CPU cores.

Git Hooks

When installed, @kdujs/cli-service also installs yorkie, which allows you to easily specify Git hooks using the gitHooks field in your package.json:

{
  "gitHooks": {
    "pre-commit": "lint-staged"
  },
  "lint-staged": {
    "*.{js,kdu}": "kdu-cli-service lint"
  }
}

Configuration without Ejecting

Projects created via kdu create are ready to go without the need for additional configuration. The plugins are designed to work with one another so in most cases, all you need to do is pick the features you want during the interactive prompts.

However, we also understand that it's impossible to cater to every possible need, and the needs of a project may also change over time. Projects created by Kdu CLI allow you to configure almost every aspect of the tooling without ever needing to eject. Check out the Config Reference for more details.