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

@xiao-edu/open

v1.1.25

Published

Powerful open tools

Downloads

2

Readme

NPM version NPM downloads GitHub GitHub language count

standard-readme compliant semantic-release commitizen friendly code style: prettier

JS gzip size

awesome-open 强大的开发者工具:Open

用于开发环境下,打开组件所在的文件

点击页面元素,即可在文件编辑器中打开组件所在的文件

目前支持 Vue 和 React

支持情况

  1. React 项目支持 React 16, React 17 等(15 及之前的版本未进行测试)
  2. Vue 项目支持 Vue 2, Vue 3

安装

使用 npm 安装(推荐)

npm i -D @xiao-edu/open

# 或者您更喜欢yarn
yarn add @xiao-edu/open -D

或者使用 CDN 引入

<!-- jsdelivr -->
<script src="https://cdn.jsdelivr.net/npm/@xiao-edu/open/dist/opener.min.js"></script>
<!-- 或者使用 unpkg -->
<script src="https://unpkg.com/@xiao-edu/open/dist/opener.min.js"></script>

使用

前端部分

在应用初始化的任意文件中引入 open 的前端部分即可

1. js 项目

在 src/index.js 中引入:

import Opener from '@xiao-edu/open'

const open = new Opener({
  // config...
})

open.init()

2. react 项目:

// src/index.js

import react from 'react'

import Opener from '@xiao-edu/open'

const open = new Opener({
  // config...
  type: 'react',
  src: react
})

open.init()

3. vue 项目:

// src/index.js

import vue from 'vue'

import Opener from '@xiao-edu/open'

const open = new Opener({
  // config...
  type: 'vue',
  src: vue
})

open.init()

开发服务器部分

配置一个 open-server:

引入 open 的后端部分即可

1. webpack

如果你使用 webpack 的 devServer 作为你的开发服务器,你可以这样写:

如在 webpack.config.js 中:

const launchEditor = require('@xiao-edu/open/server')

devServer: {
  before(app, server){
    // https://gitlab.com/lihao/awesome-open/blob/master/README-server.md
    app.use('/__open-in-editor', launchEditor('code'))
  }
}

2. umi 2.x 项目

如果你用的是 umi 2.x 版本,你可以这样修改 webpack 的配置:

import { defineConfig } from 'umi';

const launchEditorMiddleware = require('@xiao-edu/open/server');
const launchEditor = launchEditorMiddleware('code');

export default defineConfig({
    // ...config
    devServer: {
        beforeMiddlewares: [
            (req, res, next) => {
                // https://gitlab.com/lihao/awesome-open/blob/master/README-server.md
                if (req.path.startsWith('/__open-in-editor')) {
                    launchEditor(req, res, next);
                } else {
                    next();
                }
            },
        ],
    },

3. umi 3.x 项目

可以构造一个 umi 插件来用

// .umirc.ts

// https://umijs.org/config/
import { defineConfig } from 'umi'
import { join } from 'path'

const { REACT_APP_ENV } = process.env
export default defineConfig({
  // config...
  plugins: [
    /** 用于open功能的umi3插件,可以点击页面元素打开组件所在的文件 */
    join(__dirname, './umi-open-plugin')
  ]
})
// ./umi-open-plugin.ts

/**
 * preset plugins for umi3
 * 用于open功能的umi3插件,可以点击页面元素打开组件所在的文件
 */

import type { IApi } from '@umijs/types'

import launchEditorMiddleware from '@xiao-edu/open/server'
const launchEditor = launchEditorMiddleware('code')

export default function inspectorPlugin(api: IApi) {
  const OpenMiddleware = (req, res, next) => {
    // https://gitlab.com/lihao/awesome-open/blob/master/README-server.md
    if (req.path.startsWith('/__open-in-editor')) {
      launchEditor(req, res, next)
    } else {
      next()
    }
  }

  /**
   * Inspector component open file into IDE via `/__open-in-editor` api,
   * due to umi3 not use webpack devServer,
   * so need add launch editor middleware manually
   */
  api.addBeforeMiddlewares(() => OpenMiddleware)
}

4. 独立的 open server

或者你不想侵入 webpack 的开发服务器:

你可以利用 cr 的 open-server:

安装一下 cr 命令行工具:

npm i -g @xiao-edu/cr

然后启动 cr 的 open-server:

cr open --server
// or
cr o -s

然后你就可以将 open 的接口 api 前缀改为:

// src/index.js

import react from 'react'

import Opener from '@xiao-edu/open'

const open = new Opener({
  // config...
  type: 'react',
  src: react,
  api: 'http://localhost:5000/open'
})

open.init()

到这里就完成啦,去试试点击页面上的 open 按钮吧!

配置

interface IConfig {
  /** 类型,目前暂时只支持vue和react */
  type?: 'vue' | 'react'
  /** 构造函数,Vue或者React */
  /** src?: () => {} */
  src?: unknown
  /** 打开文件时的请求api前缀,默认为'/__open-in-editor' */
  api?: string
  /** 是否不打印log信息 */
  slient?: boolean
  /** 是否阻止鼠标右键的默认行为,默认是false */
  isPreventDefaultForRightClick?: boolean
  /** 显示组件名的规范,默认是'class' */
  componentNameStyle?: 'class' | 'kebab' | 'original'
}

代码贡献

  1. Fork 代码!
  2. 创建自己的分支: git checkout -b feat/xxxx
  3. 提交你的修改: git commit -am 'feat(function): add xxxxx'
  4. 推送您的分支: git push origin feat/xxxx
  5. 提交:pull request

作者

协议

MIT

🔗 链接

更新日志