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

@egglib/statics-vite

v1.0.8

Published

A eggjs plugin use to integration vite dev server

Downloads

123

Readme

@egglib/statics-vite

在 eggjs 中集成 vite 开发服务

Usage

项目搭建及开发

egg 项目创建

npm init egg
npm install

安装依赖

npm i @egglib/statics-vite

启用插件

// config/plugin.js

module.exports = {
  nunjucks: {
    enable: true,
    package: 'egg-view-nunjucks',
  },
  '@egglib/statics': {
    enable: true,
    package: '@egglib/statics-vite',
  },
};

启用视图

// config/config.default.js

module.exports = (appInfo) => {
  const config = (exports = {});

  config.keys = appInfo.name + '_1642041851507_3809';

  config.middleware = [];

  // 使用 nunjucks 作为视图模板输出界面
  config.view = {
    defaultViewEngine: 'nunjucks',
    mapping: {
      '.html': 'nunjucks',
    },
  };

  const userConfig = {};

  return {
    ...config,
    ...userConfig,
  };
};

配置开发服务

// config/config.local.js

module.exports = (appInfo) => {
  const config = (exports = {});

  // 页面资源开发服务配置
  config.statics = {
    default: appInfo.name,
    clients: {
      [appInfo.name]: {
        type: 'dev',
      },
    },
  };

  return { ...config };
};

定义路由

// app.js

module.exports = (app) => {
  // 别管那么多,直接在这里加上这句就行了
  app.addPageConfig(app.name);

  // 定义一个路由,使用 app.viewInject 方法输出页面
  app.router.get('*', app.viewInject(app.name, 'index.html'), () => {});
};

创建 vite-vue 开发相关代码,例如 vite.config.js index.html src

参考 vite + vue 搭建方法,此处略

启动开发服务

npm run dev

发布及运行生产环境

构建项目,生成 dist 目录

npm run build

启动生产环境

npm start

终止生产环境

npm stop

项目结构

egg-vitetest
├─ app
│  ├─ controller
│  │  └─ home.js
│  ├─ public
│  └─ router.js
├─ config
│  ├─ config.default.js
│  ├─ config.local.js
│  └─ plugin.js
├─ src
│  ├─ App.vue
│  └─ main.js
├─ test
│  └─ app
│     └─ controller
│        └─ home.test.js
├─ README.md
├─ app.js
├─ appveyor.yml
├─ index.html
├─ jsconfig.json
├─ package-lock.json
├─ package.json
└─ vite.config.js