Socket
Book a DemoInstallSign in
Socket

esm-optimize

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esm-optimize

optimize cjs to esm by vite

latest
Source
npmnpm
Version
1.0.8
Version published
Maintainers
2
Created
Source

ESM Optimize

拆分 vite2.0 optimize 能力,做到项目无关,同时不需要创建 vite.config 配置文件。根据入参找到具体的模块进行更新,方便上层业务根据实际情况决定要如何使用 optimize 能力。

使用方式

我们提供 cli 的形式或者模块的形式直接导入使用

$ npm i -g esm-optimize
$ esm react vue # 优化 react vue 模块
$ esm react vue --force # 删除 cache 目录 强制重新 optimize
$ esm react vue --shadowforce # 不删除 cache 目录 强制重新 optimize
$ esm react vue --config # 显示最终生成的 config
$ esm vue --withVersion # 生成后的文件带有 package.json version 版本号 include: ['vue'] => .vite/vue.2.6.12.js

生成后的文件与模块名一一对应,但如若存在多版本共存的情况则无法处理,需要上层业务手动处理。例如可能同时存在 vue2, vue3

vue -> node_modules/.vite/vue.js react -> node_modules/.vite/react.js

以模块的形式导入使用

import { optimize } from 'esm-optimize'

await optimize({
  root: string, // 默认为 cwd 
  optimizeCacheDir: string, // 默认的 vite 缓存文件夹为 `node_modules/.vite`
  optimizeDeps: {
    include: [] // 要处理的 模块
  },
  force: true, // 删除 cache文件夹 强制优化
  shadowforce: true, // 不删除 cache文件夹 强制优化
  withVersion: true // 生成后的文件带有版本号,通常使用于多版本共存的情况
})

完整配置

查看 vite 配置文档

Keywords

ssr

FAQs

Package last updated on 10 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.