Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pakholeung37/vite-plugin-treat-umd-as-commonjs
Make code runs when using requireJS/AMD in browser with vite
https://github.com/pakholeung37/vite-plugin-treat-umd-as-commonjs
amd-modules requirejs vite vite-plugin
Last synced: about 2 months ago
JSON representation
Make code runs when using requireJS/AMD in browser with vite
- Host: GitHub
- URL: https://github.com/pakholeung37/vite-plugin-treat-umd-as-commonjs
- Owner: pakholeung37
- License: mit
- Created: 2021-12-04T04:50:25.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-04T11:24:22.000Z (about 2 years ago)
- Last Synced: 2024-05-03T08:20:41.778Z (9 months ago)
- Topics: amd-modules, requirejs, vite, vite-plugin
- Language: TypeScript
- Homepage:
- Size: 56.6 KB
- Stars: 3
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vite-plugin-treat-umd-as-commonjs
Make code runs when using requireJS/amd in browser with vite. This plugin is for a paticular edge case. check [RequireJS environment in browser will break the UMD module conversion](https://github.com/vitejs/vite/issues/5900)
[![NPM](https://nodei.co/npm/vite-plugin-treat-umd-as-commonjs.png)](https://npmjs.org/package/vite-plugin-treat-umd-as-commonjs/)
## Usage
```javascript
// vite.config.js
const { defineConfig } = require("vite");
const { treatAsCommonjs } = require("vite-plugin-treat-umd-as-commonjs");module.exports = defineConfig({
plugins: [treatAsCommonjs()],
});
```It will simple add `var define = false;` in modules from node_modules by default which avoid the browser requireJS/amd environment to register the module to amd. You can also specifically include or exclude pattern.
## Options
```javascript
type Options = {
// moduleId/files to include
indluce?: Array | string | RegExp
// moduleId/files to exclude
exclude?: Array | string | RegExp
}
```## License
[MIT](LICENSE)