npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kkt/ssr

v3.1.13

Published

<p align="center"> <a href="https://kktjs.github.io/ssr"> <img src="https://user-images.githubusercontent.com/1680273/157196191-9e56f20a-8991-487a-a78d-35352a2c1222.png"> </a> </p>

Downloads

26

Readme

Create React server-side rendering universal JavaScript applications with no configuration. If you don't need server-side rendering you can use kkt tools.

Quick Start · Using Plugins · Rewrite Config · KKTSSR Config · Example

Let's fund issues in this repository

Usage

You will need Node.js installed on your system. Support multiple webpack configurations to execute together.

Command Help


  Usage: kkt-ssr [build|start] [--help|h]

  Displays help information.

  Options:

   --version, -v         Show version number
   --help, -h            Displays help information.
   --s-ne, --s-nodeExternals          server use webpack-node-external .
   --c-ne, --c-nodeExternals          client use webpack-node-external .
   --s-st, --s-split          server Split code .
   --c-st, --c-split          client Split code .
   -o, --original          Use original react-scripts config .
   -m, --minify          All Minify output.
   --s-m, --s-minify          server Minify output.
   --c-m, --c-minify          clinet Minify output.
   --target                   clent or server or all.

  Example:

   $ kkt-ssr build
   $ kkt-ssr start
   $ kkt-ssr build --s-ne
   $ kkt-ssr start --s-ne
   $ kkt-ssr build --s-st
   $ kkt-ssr start --s-st
   $ kkt-ssr start -o

Quick Start

npx create-kkt-ssr my-app
cd my-app
npm install
npm run start

You can also initialize a project from one of the examples. Example from kktjs/ssr example-path.

# Using the template method
# `npx create-kkt-ssr my-app [-e example name]`
npx create-kkt-ssr my-app -e react-router-rematch

or

npm install -g create-kkt-ssr
# Create project, Using the template method
create-kkt-ssr my-app -e react-router-rematch
cd my-app # Enter the directory
npm install # Watch file
npm run start # Start service

⚠️ A perfect example react-router-rematch is recommended for production environments, This example is similar to Next.js.

development

Runs the project in development mode.

npm run start

production

Builds the app for production to the build folder.

npm run build

The build is minified and the filenames include the hashes. Your app is ready to be deployed!

# Runs the compiled app in production.
npm run server

Using Plugins

Add .kktssrrc.js to the root directory of your project

import pluginLess from "@kkt/plugin-less"
import { Options } from "@kkt/ssr/lib/interface"

export default {

  overridesCommonWebpack: (conf:webpack.Configuration,env:"development" | "production",options:Options) => {

    const newConfig = pluginLess(conf, {
      target: conf.target==="node14"?"node":"web",
      env,
      paths: options.paths
    })

    return newConfig
  },

};

See All Plugins

Rewrite Config

Add .kktssrrc.js to the root directory of your project

Rewrite Client Config

import { Options } from "@kkt/ssr/lib/interface"

export default {

  overridesClientWebpack:(conf:webpack.Configuration,env:"development" | "production",options:Options)=>{

    return conf

  }

}

Rewrite Server Config

  1. devtool: The default is false,
  2. target: The default is node,
  3. output.library.type: The default is commonjs,
import { Options } from "@kkt/ssr/lib/interface"

export default {

  overridesServerWebpack:(conf:webpack.Configuration,env:"development" | "production",options:Options)=>{

    return conf

  }

}

More Webpack Config

import { Options } from "@kkt/ssr/lib/interface"

export default {

  overridesWebpack:(conf:webpack.Configuration[],env:"development" | "production",options:Options)=>{

    return conf

  }

}

Rewrite Env

export default {
  
  /** 环境变变量/Environmental variable */
  env:{
    GENERATE_SOURCEMAP: "false",
    INLINE_RUNTIME_CHUNK: "false",
    ESLINT_NO_DEV_ERRORS: "false",
    DISABLE_ESLINT_PLUGIN: "false",
  },
 
}

Rewrite Paths

other paths

export default {

  paths:{

    appBuild: path.join(process.cwd(),"dist")

  }

}

Rewrite build output path

  1. server_path: The default is src/server.js.
  2. client_path: The default is src/client.js.
  3. output_path: The default is dist.

export default {

  /** 服务端打包入口/Server packaging entry  */
  server_path: path.join(process.cwd(),"src/server.js"),
  /** 客户端打包入口/Client packaging entry */
  client_path: path.join(process.cwd(),"src/client.js"),
  /** 输出文件地址/Output address */
  output_path: path.join(process.cwd(),"dist");

}

proxySetup

Reference mocker-api


export default {

  proxySetup: (app) => ({
    path: "./mocker/index.js",
    options:{
      changeHost: true,
      proxy:{

      }
    }
  }),

}

DefinePlugin

  1. OUTPUT_PUBLIC_PATH: The default is path.join(process.cwd(),"dist")
  2. KKT_PUBLIC_DIR: The default is process.env.KKT_PUBLIC_DIR or OUTPUT_PUBLIC_PATH
  3. HOST: The default is process.env.HOST or localhost
  4. PORT: The default is process.env.PORT or 3000
  5. HOSTAPI: The default is undefined , 当运行start命令时值为http://${HOST}:${PORT}
  6. process.env.PORT: 默认值 3000
  7. process.env.HOSTAPI: The default is undefined , 当运行start命令时值为http://${HOST}:${PORT}
  8. process.env.HOST: The default is localhost

KKTSSR Config

The root directory creates the .kktssrrc.js file.

| 参数 | 类型 | 默认值 | 说明 | | -------- | -------- | --------------- | --------- | | overridesClientWebpack | (conf: webpack.Configuration, env: "development" \| "production", options: Options) => webpack.Configuration | undefined | 覆写客户端配置 | | overridesServerWebpack | (conf: webpack.Configuration, env: "development" \| "production", options: Options) => webpack.Configuration | undefined | 覆写服务端配置 | | overridesCommonWebpack | (conf: webpack.Configuration, env: "development" \| "production", options: Options) => webpack.Configuration| undefined | 公共覆盖配置 | | overridesWebpack| (conf: webpack.Configuration[], env: "development" \| "production", options: Options) => webpack.Configuration[] \| webpack.Configuration | undefined| 最终的配置 | | server_path | string | src/server.js | 服务端打包入口 | | client_path | string| src/client.js | 客户端打包入口 | | output_path| string | dist | 输出文件地址 | | isUseOriginalConfig| boolean | false | 是否使用原始 react-script 下的配置 | | isUseServerConfig | boolean | true | 是否需要 server 配置 | | paths | Partial<Paths> | {} | paths 脚本中webpack配置 使用的地址 | | proxySetup | (app:Application)=>({path:stirng\|string[],options:MockerOption}) | undefined| mock 代理配置 |

 // Modify the webpack config
export default {
  
};

Example

A complete react + react-router + rematch(redux) example is recommended for production projects, similar to next.js. Initialize the project from one of the examples:

npx create-kkt-ssr my-app -e react-router-rematch

Contributors

As always, thanks to our amazing contributors!

Made with github-action-contributors.

License

Licensed under the MIT License