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

webpack-koa-hot-reload

v1.1.0

Published

用webpack打包koa应用时,在开发阶段基于nodemon的热重载

Downloads

5

Readme

webpack-koa-hot-reload

为什么做了个

准备开发一个koa应用 应用技术为 koa + prisma + mysql 然后就是各种中间件来实现我的api服务。但是在开发阶段发现 koa-webpack 和web的一些插件 对于我来说好像不适用,因为我需要webpack来打包ts代码 然后输出为node平台运行。其他的中间件需要在koa中编写代码,这不是我想要的 我想要的只是一个 热重载,于是制作了这个小插件,如果你跟我一样希望使用webpack来打包koa应用 希望有热重载来方便开发 但又不想写侵入式代码 那就来试试吧

怎么使用

打开你的webpack.config.js 我用的是 webpack.config.ts

对应的引用方式为

const WebpackKoaHotReload = require('webpack-koa-hot-reload') | import WebpackKoaHotReload from 'webpack-koa-hot-reload'

完整示例

1.webpack.config.ts

  import WebpackKoaHotReload from 'webpack-koa-hot-reload';
  
  
  const config: webpack.Configuration = {
  target:"node",
  ....
  watchOptions: {
    poll:1000,//监测修改的时间(ms)
    aggregateTimeout:500,//500毫秒内算按键一次
    ignored: /node_modules/,
  },
  plugins:[
    new WebpackKoaHotReload({
      main: path.join(__dirname,'dist/index.js'),
      port:'3000',
    })
  ],
  module:{
    rules:[
      {
        test:/\.ts$/,
        use:'ts-loader',
        exclude:/node_modules/
      }
    ]
  },
  resolve:{
    extensions:['.ts','.js']
  }
};

export default config;

2.koa应用入口文件 一般为index.js/index.ts 最后一行app.listen请注意

  import Koa from 'koa';
  import Router from 'koa-router'
  const app = new Koa();
  const router = new Router()
  router.get('/', async (ctx)=>{
    ctx.body = 'hello'
  })
  app.use(async ctx => {
    ctx.body = 'Hello';
  });
  app.listen(process.argv[2]);

需要其他配置请给我留言

插件参数

| 参数名 | 类型 | 默认值 | 必填 | 描述 | | :----: | :----: | :----: | :--: | -------- | | main | string | 无 | 是 | 入口文件 | | port | number | 8573 | 否 | 端口 | | delay | number | 0 | 否 | 延迟重载 |

--- enjoy ---