|
| 1 | +# babel-plugin-transform-vite-meta-hot |
| 2 | + |
| 3 | +<!-- prettier-ignore-start --> |
| 4 | +[](https://github.com/OpenSourceRaidGuild/babel-vite/actions?query=workflow%3Avalidate) |
| 5 | +[](https://codecov.io/gh/OpenSourceRaidGuild/babel-vite) |
| 6 | +[](https://www.npmjs.com/package/babel-plugin-transform-vite-meta-hot) |
| 7 | +[](http://www.npmtrends.com/babel-plugin-transform-vite-meta-hot) |
| 8 | +[](https://github.com/OpenSourceRaidGuild/babel-vite/blob/master/LICENSE.md) |
| 9 | + |
| 10 | +[](http://makeapullrequest.com) |
| 11 | +[](https://github.com/OpenSourceRaidGuild/babel-vite/blob/master/CODE_OF_CONDUCT.md) |
| 12 | +[](https://discord.gg/grS89HWeYh) |
| 13 | + |
| 14 | +[](https://github.com/OpenSourceRaidGuild/babel-vite/watchers) |
| 15 | +[](https://github.com/OpenSourceRaidGuild/babel-vite/stargazers) |
| 16 | +[](https://twitter.com/intent/tweet?text=Check%20out%20babel-plugin-transform-vite-meta-hot%20by%20OpenSourceRaidGuild%20https%3A%2F%2Fgithub.com%2FOpenSourceRaidGuild%2Fbabel-vite%20%F0%9F%91%8D) |
| 17 | +<!-- prettier-ignore-end --> |
| 18 | + |
| 19 | +> Please note: this plugin is intended to provide an approximation of some of Vite specific |
| 20 | +> transformations when running the code in non-Vite environment, for example, running tests with a |
| 21 | +> NodeJS based test runner. |
| 22 | +> |
| 23 | +> **The functionality within these transformations should not be relied upon in production.** |
| 24 | +
|
| 25 | +## Example |
| 26 | + |
| 27 | +**In** |
| 28 | + |
| 29 | +``` |
| 30 | +if (import.meta.hot) { |
| 31 | + import.meta.hot.accept(callback); |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +**Out** |
| 36 | + |
| 37 | +``` |
| 38 | +if (module.hot) { |
| 39 | + module.hot.accept(callback); |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +## Installation |
| 44 | + |
| 45 | +```sh |
| 46 | +npm install --save-dev babel-plugin-transform-vite-meta-hot |
| 47 | +``` |
| 48 | + |
| 49 | +## Usage |
| 50 | + |
| 51 | +### With a configuration file (Recommended) |
| 52 | + |
| 53 | +```json |
| 54 | +{ |
| 55 | + "plugins": ["babel-plugin-transform-vite-meta-hot"] |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +### Via CLI |
| 60 | + |
| 61 | +```sh |
| 62 | +babel --plugins babel-plugin-transform-vite-meta-hot script.js |
| 63 | +``` |
| 64 | + |
| 65 | +### Via Node API |
| 66 | + |
| 67 | +```javascript |
| 68 | +require('@babel/core').transformSync('code', { |
| 69 | + plugins: ['babel-plugin-transform-vite-meta-hot'] |
| 70 | +}) |
| 71 | +``` |
0 commit comments