当前位置:网站首页>Viteproject require Syntax Compatibility Problem Solving require is not defined
Viteproject require Syntax Compatibility Problem Solving require is not defined
2022-06-30 08:27:00 【Studio tianmiao】
viteLe projet ne soutient pasrequireRésolution de problèmes de grammaire require is not defined
ViteUtilisation par défautes6Standard import Méthode d'importation pour,Non pris en chargerequireIntroduction.Par défautViteLa façon dont ils ont été introduitshttps://vitejs.cn/guide/assets.html
Mais dans l'usage quotidienVue3+Ts+ViteDans le projet de construction,Certaines sont plus anciennesDans le plug - in tripartitePar défautrequireIntroduction(webpackBuild peut utiliser),Ça va arriver.requireProblèmes de compatibilité des erreurs de méthode require is not defined .
1. requireEtimportDifférences d'importation
| Année | Origine | Utiliser | |
|---|---|---|---|
| require/exports | 2009 | CommonJS | const lodash = require(‘lodash’); |
| import/export | 2015 | ECMAScript2015(ES6) | import lodash from ‘lodash’; |
2. Solutions
Vite Écologie communautaire des entrepôts https://github.com/vitejs/awesome-viteL'un d'eux
Plug - in vite-plugin-require-transform. Conversion automatique du plug - inimport xxx from ‘’;Méthodes Introduction
Installation
yarn add -D vite-plugin-require-transform
Ou
npm i vite-plugin-require-transform --save-dev
Utiliser
// vite.config.tsConfiguration
import requireTransform from 'vite-plugin-require-transform';
plugins: [
// ...
requireTransform({
fileRegex:/.ts$|.tsx$|.vue$/
// fileRegex:/.js$|.jsx$|.vue$/
}),
]
Après additionnpm run buildEmballez npm run preview Aucune exception à l'aperçu .
边栏推荐
- Conversion between map, string and JSON
- Axure制作菜单栏效果
- 1163 Dijkstra Sequence
- A troubleshooting of CPU bottom falling
- Dlib library blink
- [JUC series] overview of fork/join framework
- Full stack performance testing theory - Summary
- Enter the URL in the browser and display it on the page
- Does the oscilloscope probe affect the measurement of capacitive load?
- Introduction to opencv (II): image color space conversion and image saving
猜你喜欢

【NVMe2.0b 14】NVMe Admin Command Set

F12 packet capture is used for the whole process analysis of postman interface test

Opencv4.2.0+vs2015 configuration

Acreems energy efficiency management platform escorts the power safety of high-rise residential areas

【NVMe2.0b 14-5】Firmware Download/Commit command

Sword finger offer II 075 Array relative sort (custom sort, count sort)

【NVMe2.0b 14-6】Format NVM、Keep Alive、Lockdown command

Redis设计与实现(二)| 数据库(删除策略&过期淘汰策略)

一次cpu 跌底排查

Game 280 problem2: minimum operands to turn an array into an alternating array
随机推荐
【NVMe2.0b 14-4】Directive Send/Receive command
Graffiti Wi Fi & ble SoC development slide strip
【NVMe2.0b 14-6】Format NVM、Keep Alive、Lockdown command
Cesium learning notes (II) uploading data using rest API
MIME type Encyclopedia
Sword finger offer II 075 Array relative sort (custom sort, count sort)
Unity简单shader
【NVMe2.0b 14-5】Firmware Download/Commit command
2021-02-18
Redis设计与实现(五)| Sentinel哨兵
F12 packet capture is used for the whole process analysis of postman interface test
[nvme2.0b 14 - 5] commande de téléchargement / commande du logiciel
Interference source current spectrum test of current probe
Common tools installation, configuration, compilation, link, etc
Dart tips
Introduction to opencv (II): image color space conversion and image saving
电流探头的干扰源电流谱测试
C# ListBox如何获取选中的内容(搜了很多无效的文章)
Introduction to opencv (I): image reading and display
【NVMe2.0b 14-6】Format NVM、Keep Alive、Lockdown command