[英]How to define alias to url in webpack config similarly to vite
using Vite to generate a VueJs project npm init vue@latest
I get the following alias in the configuration file vite.config.js
:使用Vite生成 VueJs 项目npm init vue@latest
我在配置文件vite.config.js
中得到以下别名:
import { fileURLToPath, URL } from 'node:url'
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
Replacing the upper chunck of code in webpack v5
(for another project):替换webpack v5
中的上部代码块(用于另一个项目):
const { fileURLToPath, URL } = require("url")
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
yields the following error:产生以下错误:
'@': fileURLToPath(new URL('./src', import.meta.url))
SyntaxError: Cannot use 'import.meta' outside a module
Can you please tell me how can I replace the aliasing correctly in webpack v5
?您能告诉我如何在webpack v5
中正确替换别名吗? thank in advance.预先感谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.