Skip to content

Commit

Permalink
feat: Add @kkt/ncc package.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Feb 22, 2022
1 parent 6209c5c commit a569191
Show file tree
Hide file tree
Showing 12 changed files with 487 additions and 1 deletion.
16 changes: 16 additions & 0 deletions example/bundle-node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
dist
build
node_modules
npm-debug.log*
package-lock.json
.eslintcache
.DS_Store
.cache
.vscode

*.bak
*.tem
*.temp
#.swp
*.*~
~*.*
20 changes: 20 additions & 0 deletions example/bundle-node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Basic Example for bundle-node
===

Simple CLI for compiling a Node.js module into a single file, together with all its dependencies, gcc-style. A tool created based on [`kkt`](https://github.com/kktjs/kkt) & [`create-react-app`](https://github.com/facebook/create-react-app), [`@kkt/ncc`] similar to [@vercel/ncc](https://www.npmjs.com/package/@vercel/ncc)

## Quick Start

```bash
$ npx create-kkt my-app -e bundle-node
cd my-app
npm install
```

**production**

Builds the app for production to the build folder.

```bash
npm run build
```
31 changes: 31 additions & 0 deletions example/bundle-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@template/bundle-node",
"version": "7.1.0",
"description": "",
"private": true,
"scripts": {
"build": "npm run bundle && npm run bundle:min",
"bundle": "ncc build src/app.ts",
"watch": "ncc start src/app.ts",
"bundle:min": "ncc build src/app.ts -m"
},
"repository": {
"type": "git",
"url": "https://github.com/kktjs/kkt.git"
},
"author": "",
"license": "MIT",
"dependencies": {
"@types/hapi__hapi": "20.0.10",
"@hapi/hapi": "20.2.1"
},
"devDependencies": {
"@kkt/ncc": "1.0.0"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
}
}
26 changes: 26 additions & 0 deletions example/bundle-node/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Hapi from '@hapi/hapi';

const init = async () => {
const server = new Hapi.Server({
port: 3000,
host: 'localhost',
});

server.route({
method: 'GET',
path: '/',
handler: (request, h) => {
return 'Hello World!';
},
});
console.log('WCJ');
await server.start();
console.log('Server running on %s', server.info.uri);
};

process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
});

init();
18 changes: 18 additions & 0 deletions example/bundle-node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "es2015",
"moduleResolution": "node",
"allowJs": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"isolatedModules": true,
"declaration": true,
"noFallthroughCasesInSwitch": true,
"baseUrl": "./src",
"noEmit": false
},
"include": ["src/**/*", ".kktrc.ts"]
}
13 changes: 12 additions & 1 deletion example/bundle/.kktrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ export default (conf, env, options) => {
...pkg,
// webpack externals options
dependencies: {
...pkg.dependencies,
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react',
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom',
},
'react-refresh': '0',
},
});
Expand Down
56 changes: 56 additions & 0 deletions packages/ncc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@kkt/ncc
===

Simple CLI for compiling a Node.js module into a single file, together with all its dependencies, gcc-style. A tool created based on [`kkt`](https://github.com/kktjs/kkt) & [`create-react-app`](https://github.com/facebook/create-react-app), [`@kkt/ncc`] similar to [@vercel/ncc](https://www.npmjs.com/package/@vercel/ncc)

## Usage

### Installation

```bash
npm i -g @kkt/ncc
```

### Usage

```bash
$ ncc <cmd> [input-file] [opts]
# input-file default value: src/index.ts
```

### Eg:

```bash
$ ncc build input.js -o dist
```

Outputs the `Node.js` compact build of `input.js` into `dist/input.js`.

## Commands

```bash
Usage: ncc [build] [input-file] [--help|h]

Displays help information.

Options:

--version, -v Show version number
--help, -h Displays help information.
-o, --out [dir] Output directory for build (defaults to dist).
-m, --minify Minify output.
-s, --source-map Generate source map.
-e, --external [mod] Skip bundling 'mod'. Can be used many times.

Example:

$ ncc build
$ ncc build --out ./dist
$ ncc build --minify
$ ncc build src/app.ts
$ ncc build --source-map
```

### License

Licensed under the MIT License
25 changes: 25 additions & 0 deletions packages/ncc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@kkt/ncc",
"version": "1.0.0",
"description": "Simple CLI for compiling a Node.js module into a single file, together with all its dependencies, gcc-style.",
"author": "Kenny Wong <wowohoo@qq.com> (https://github.com/jaywcjlove)",
"repository": "https://github.com/kktjs/kkt/tree/master/packages/ncc",
"license": "MIT",
"bin": {
"ncc": "./lib/index.js"
},
"keywords": [
"kkt",
"ncc",
"nodejs",
"cra",
"build-tools",
"create-react-app",
"zero-configuration",
"framework"
],
"dependencies": {
"css-minimizer-webpack-plugin": "3.3.1",
"kkt": "7.1.0"
}
}

0 comments on commit a569191

Please sign in to comment.