{"name":"vite-plugin-externals","version":"0.5.2","description":"externals plugin for vite","author":{"name":"crcong"},"repository":{"type":"git","url":"git+https://github.com/crcong/vite-plugin-externals.git"},"homepage":"https://github.com/crcong/vite-plugin-externals","bugs":{"url":"https://github.com/crcong/vite-plugin-externals/issues"},"license":"MIT","scripts":{"dev":"tsc -w","build":"pnpm lint:fix && rimraf dist && tsc && pnpm build:es","build:es":"tsc --module ESNEXT --outDir dist/es","lint:fix":"eslint --fix ./src/**/*.ts","test":"vitest","release":"pnpm build && bumpp --push --tag --commit && npm publish"},"keywords":["vite-plugin","external","externals"],"types":"index.d.ts","main":"dist/index.js","module":"dist/es/index.js","peerDependencies":{"vite":">=2.0.0"},"engines":{"node":"^14.18.0 || >=16.0.0"},"devDependencies":{"@crcong/eslint-config-typescript":"^0.3.0","@types/estree":"^0.0.48","@types/fs-extra":"^9.0.12","@types/node":"^17.0.45","@types/ws":"^8.2.2","bumpp":"^7.1.1","eslint":"^8.0.1","rimraf":"^3.0.2","rollup":"^2.51.2","typescript":"^4.8.3","vite":"^2.7.1","vitest":"^0.22.1"},"dependencies":{"acorn":"^8.4.0","es-module-lexer":"^0.4.1","fs-extra":"^10.0.0","magic-string":"^0.25.7"},"gitHead":"cb6788ff8ed9f418c5bd8331bca94a435064a7f9","_id":"vite-plugin-externals@0.5.2","_nodeVersion":"16.17.0","_npmVersion":"8.15.0","dist":{"integrity":"sha512-qWmMmDR4tUoROdNqMwKZXZoWREXtLxlgDdIeCJV3wcRZ4vc4FphTUzy3pN5A1+fOLyI9Vxc7Yl/94QjreYFHuQ==","shasum":"9209499353eeb45256b4fee964ea9c646cb29a30","tarball":"http://registry-npm.ywwl.com/vite-plugin-externals/download/vite-plugin-externals-0.5.2.tgz","fileCount":33,"unpackedSize":37723,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICnterFHMh7M9E5IAMerqV2q5d46zS1w+EFMC9ejhiXOAiEA4x9rvdHOw2PwoqWDgzSNyst9VIPcSXiNUoQF6y1mp5E="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj1nQ5ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrpAw/5AUSxCQiXh32oiEGfOAR+8OKsum731KqGBognd8a2YZHokH+s\r\nZ2y+kbzkUptXBw6I/wyf0UACegFEiJVMHmw3Qt8e3xyJqAPEh5KIYBLYpfIx\r\nNPkxnby1oFwPS3rB7w3lRlzv6YZjEE8q/spIcYsgKeuYhsspD1JGNARZtsdb\r\nZmhpHRFZkOAO/r2UYVXGB8OSrpKG0WquxbmDrmua4GcI+8rN/iDKJfKcOyDh\r\nXoi8IyEDUnf7eDN3UZvrCmf+gzoV7TyCARHauxxVs3S5D3Ow0cK2667SS58s\r\nBEfqfrqafYug+NFoEFVx0nOkUxa5kg7A7BqKjoiijVUGYVIjJZEeGzZrtfi9\r\n5G2LX2c2k90XVT8Id+X9WnuPUoKddoR0wV57JQaHVMjkloYxvsutdP5bCTXK\r\nZKJMnpkoTZ0dcHv18UpsTQUPRd9SpULjsps7zXhhlSp9mKPbRdS2wtMLxkem\r\nyGuAW3JGFnJ6eRLJB3Fiwwqj3/kGn2q+LkYhdnjH977sDoxqc83ly0HnXRMs\r\nl07Wry/3770pFAmxtYkWCx+Gkb3f36BBHIM7ZHM8PgTynb5Y/QTezAP/56FC\r\nQq2KzjGybc6fgqho15MvQl4/CzDlycaIsdNVb9gCqcHiP5UJ7rpvb+uuUFNp\r\nIkqc1oFh72RZ5CKL2oy/zWWWHUwG+16WZNA=\r\n=YYJm\r\n-----END PGP SIGNATURE-----\r\n","size":8372,"noattachment":false,"key":"/vite-plugin-externals/-/vite-plugin-externals-0.5.2.tgz"},"_npmUser":{"name":"crcong","email":"crcong@foxmail.com"},"directories":{},"maintainers":[{"name":"crcong","email":"crcong@foxmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/vite-plugin-externals_0.5.2_1674998841772_0.3616651405075728"},"_hasShrinkwrap":false,"readme":"# vite-plugin-externals\n\n<p>\n  <a href=\"https://www.npmjs.com/package/vite-plugin-externals\" target=\"_blank\">\n    <img alt=\"NPM package\" src=\"https://img.shields.io/npm/v/vite-plugin-externals.svg?style=flat\">\n  </a>\n  <a href=\"https://www.npmjs.com/package/vite-plugin-externals\" target=\"_blank\">\n    <img alt=\"downloads\" src=\"https://img.shields.io/npm/dt/vite-plugin-externals.svg?style=flat\">\n  </a>\n  <a href=\"https://github.com/vitejs/awesome-vite#helpers\" target=\"_blank\">\n    <img src=\"https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg\" alt=\"Awesome\">\n  </a>\n</p>\n\nEnglish | [简体中文](README.zh-CN.md)\n\nuse to external resources, like webpack externals, but only use in browser now.\n\nCan be used in `production` mode without other `rollup` configuration.\n\nbut it will not take effect by default in `commonjs`, such as `ssr`.\n\n## Usage\n\n```bash\nnpm i vite-plugin-externals -D\n```\n\nAdd it to `vite.config.js`\n\n```js\n// vite.config.js\nimport { viteExternalsPlugin } from 'vite-plugin-externals'\n\nexport default {\n  plugins: [\n    viteExternalsPlugin({\n      vue: 'Vue',\n      react: 'React',\n      'react-dom': 'ReactDOM',\n      // value support chain, transform to window['React']['lazy']\n      lazy: ['React', 'lazy']\n    }),\n  ]\n}\n```\n\n**Warning**: If you loaded `production` library in `vite dev mode` , may make `HMR` **fail**.\n\nYou can use `disableInServe: true` option to avoid transform in serve mode.\n\nEg.\n```html\n<!-- may make HMR fail -->\n<script src=\"./vue.global.prod.js\"></script>\n\n<!-- good -->\n<script src=\"./vue.global.js\"></script>\n```\n\n## How to work\n\ntransform source code of js file.\n\n```js\n// configuration\nviteExternalsPlugin({\n  vue: 'Vue',\n}),\n// source code\nimport Vue from 'vue'\n// transformed\nconst Vue = window['Vue']\n\n// source code\nimport { reactive, ref as r } from 'vue'\n// transformed\nconst reactive = window['Vue'].reactive\nconst r = window['Vue'].ref\n\n// source code\nimport * as vue from 'vue'\n// transformed\nconst vue = window['Vue']\n\n// source code\nexport { useState as _useState } from 'react'\n// transformed\nexport const _useState = window['React'].useState\n```\n\n**Warning**: please use the plugin after converting to JS code, because the plugin only transform JS code. Eg.\n\n```js\nimport vue from '@vitejs/plugin-vue'\n\nexport default {\n  plugins: [\n    vue(), // @vitejs/plugin-vue will transform SFC to JS code\n\n    // It should be under @vitejs/plugin-vue\n    viteExternalsPlugin({\n      vue: 'Vue',\n    }),\n  ]\n}\n```\n\nIf an error occurs, you can check whether the error is caused by the plugin order.\n\n## Configuration\n\n### disableInServe\n\ndisable transform in `serve mode` .\n\n```js\nviteExternalsPlugin({\n  vue: 'Vue',\n}, { disableInServe: true })\n```\n\n\n### enforce\n\nvite plugin ordering. Resolve plugin ordering cause unexpected error. Such as [#21](https://github.com/crcong/vite-plugin-externals/issues/21).\n\nSee [https://vitejs.dev/guide/api-plugin.html#plugin-ordering](https://vitejs.dev/guide/api-plugin.html#plugin-ordering).\n\n### filter\n\nThe files in `node_modules` are filtered by default, and only transform js/ts/vue/jsx/tsx file.\n\nYou can specify the `filter` function. Return `true` will be transform to external.\n\n```js\nviteExternalsPlugin({\n  vue: 'Vue',\n}, {\n  filter(code, id, ssr) {\n    // your code\n    return false\n  }\n}),\n```\n\n### useWindow\n\nset `false`, the `window` prefix will not be added.\n\n**Warning**: If your module name has special characters, such as `/`, set useWindow option `false`, will throw error.\n\n```js\nviteExternalsPlugin({\n  vue: 'Vue',\n}, { useWindow: false }),\n\n// source code\nimport Vue from 'vue'\n// transformed, no `const Vue = window['Vue']`\nconst Vue = Vue\n```\n\n### sourceMapOptions\n\nThe configuration item of the code sourcemap after code conversion. The library is `magic-string`.\n","publish_time":1674998841926,"_cnpm_publish_time":1674998841926,"dist-tags":{"latest":"0.6.2"}}