1.4.6 • Published 5 years ago

kaonjs v1.4.6

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

kaon.js

Kaon.js is an react isomorphic app solution. it contains webpack build, hot reloading, code splitting and server side rendering.

From

Kaon is a Decepticon-controlled city-state in the southern hemisphere of Cybertron. Under Decepticon rule, its capitol is the fortress of Kolkular.

The pronounce

'keɑn

The main stack

  • koa
  • react
  • redux
  • react-router
  • react-helmet
  • webpack
  • postcss
  • react-hot-loader
  • loadable-components
  • babel

Usage

install

npm install kaonjs

or with yarn

yarn add kaon

add your config

Config is a js file that default exported a Javascript object, it specified a lot ot configurations. The default path is <project_root>/config/kaon.config.js. But you can put it into anywhere of your project.

The config file is not required, Kaon will use the default config as below:

const kaonConfig = {
  ssr: true,
  app: {
    name: 'Kaon Config Template (production)',
    shortName: 'rib',
    port: 1827,
    routes: `${baseDir}/app/routes`,
    middlewares: `${baseDir}/app/middlewares`,
  },
  resources: {
    root: `${baseDir}/public`,
  },
  isomorphic: {
    routes: `${baseDir}/src/routes`,
    store: `${baseDir}/src/store/configureStore.js`,
    main: `${baseDir}/src/client`,
  },
  postcss: {
    path: `${baseDir}/config/postcss.config.js`,
  },
  webpack: {
    client: `${baseDir}/config/webpack.client.config`,
    server: `${baseDir}/config/webpack.server.config`,
  },
  build: {
    host: 'localhost',
    port: 1592,
    path: 'build/',
    target: `${baseDir}/public/build`,
  },
};

An configuration specified these optons:

ssr

Enable or disable server side side rendering. Disable ssr will improve start up speed.

i18n

app

  • app.name - The app name
  • app.shortName - The short app name.
  • app.port - App listening port.
  • app.routes - Customize koa routes.
  • app.middlewares - the js file that will apply your middlewares.

resources

  • resources.root - If resources.root is exist, kaon will serve all files inside the path as static server.

isomorphic

  • isomorphic.routes - The client routes path, should be an string, the default value is <project_root>/src/routes.
  • isomorphic.store - The client store path, should be an string, the default value is <project_root>/src/store/configureStore
  • isomorphic.main - The client entry

postcss

  • postcss.path - If use postcss, shoud specify postcss path.

webpack

  • webpack.client - your client webpack configuration, object or function.
  • webpack.server - your server webpack configuration, object or function.

build

  • build.host - The dev server will server at this host.
  • build.port - the dev server port.
  • build.path - the dev server url path.
  • build.target - the build result path.

command line

command: kaon <cmd> [options]

commands

kaon start [options]

available options:

  • config - specify config path

kaon build [options]

available options:

  • config - specify config path

nodejs APIs

You can use kaon as an npm modules instead of cli.

const Kaon = require('kaon');
const kaon = new Kaon(config);

kaon.start();

environment variables

ENABLE_SSR

yes or no. If select yes, server side rendering will be enabled, no will disable server side rendering temporary.

apply your middleware.

First, configure your middleware path, it should be a javascript file like below:

const logger = require('koa-logger');
const favicon = require('koa-favicon');
const path = require('path');

function applyMiddlewares(app) {
  app.use(logger());
  app.use(favicon(path.join(__dirname, '../../public/favicon.ico')));
}

module.exports = applyMiddlewares;

The app instance will be passed to your function, then just call app.use to apply the middlewares.

apply your routes.

Just like apply middlewares. just don't forget configure your routes path in your config file.

const Router = require('koa-router');

function applyRoutes(app) {
  const router = new Router();

  router.get('/', async (ctx) => {
    ctx.body = 'hello world.';
  });

  app.use(router.routes());
  app.use(router.allowedMethods());
}

module.exports = applyRoutes;

add your customize script, styles, head tags, ect.

You can use react-helmet.

apply your own webpack configuration.

ATTENTION! You cannot override default entry with yours.

pm2 graceful reload

add the below configuration to your pm2

module.exports = {
  apps : [{
    name: "api",
    script: "./api.js",
    wait_ready: true,
    listen_timeout: 3000,
  }],
}

License

MIT

1.4.6

5 years ago

2.1.7

5 years ago

2.1.6

5 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

2.0.0-aplha-4

5 years ago

2.0.0-alpha-3

5 years ago

1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

2.0.0-alpha-2

6 years ago

2.0.0-aplha

6 years ago

2.0.0-0

6 years ago

1.4.0

6 years ago

1.3.18

6 years ago

1.3.17

6 years ago

1.3.16

6 years ago

1.3.15

6 years ago

1.3.14

6 years ago

1.3.13

6 years ago

1.3.12

6 years ago

1.3.10

6 years ago

1.3.9

6 years ago

1.3.8

6 years ago

1.3.7

6 years ago

1.3.6

6 years ago

1.3.5

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.0

6 years ago

2.0.0-alpha-1

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.0.0-beta-1

6 years ago

1.0.0-alpha-2

6 years ago

1.0.0-alpha-1

6 years ago

0.6.9

6 years ago

0.6.8

6 years ago

0.6.7

6 years ago

0.7.0-alpha-5

6 years ago

0.7.0-alpha-4

6 years ago

0.7.0-alpha-3

6 years ago

0.7.0-alpha-2

6 years ago

0.7.0-alpha-1

6 years ago

0.7.0-rc3

6 years ago

0.7.0-rc2

6 years ago

0.6.6

6 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.3-rc1

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.15

6 years ago

0.5.14

6 years ago

0.5.13

6 years ago

0.5.12

6 years ago

0.5.11

6 years ago

0.5.10

6 years ago

0.5.9

6 years ago

0.5.8

6 years ago

0.5.7

6 years ago

0.5.6

6 years ago

0.5.5

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.14

6 years ago

0.4.13

6 years ago

0.4.12

6 years ago

0.4.11

6 years ago

0.4.10

6 years ago

0.4.9

6 years ago

0.4.8

6 years ago

0.4.7

6 years ago

0.4.6

6 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.19

6 years ago

0.3.18

6 years ago

0.3.17

6 years ago

0.3.16

6 years ago

0.3.15

6 years ago

0.3.14

6 years ago

0.3.13

6 years ago

0.3.12

6 years ago

0.3.11

6 years ago

0.3.10

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago