赞
踩
项目中引入文件,通常是
import a from '../common/b'//表示src/common/b
有些公共组件更是嵌套多层,所以使用符号@/,表示src/的路径
使用
import a from '@/common/b'//表示src/common/b
环境:
"react": "^17.0.1",
"webpack": "4.44.2",
- {
- "compilerOptions": {
- "experimentalDecorators": true,
- "baseUrl": ".",
- "paths": {
- "@/*": ["src/*"]
- },
- "jsx": "react"
- },
- "exclude": ["node_modules", "build", "config", "scripts"]
- }
查找alias,在其内部加入以下代码
"@": path.resolve(__dirname, "../src"),
环境:
"next": "10.0.5",
- const path = require("path");
- module.exports = {
- webpack: (config) => {
- config.resolve.alias["@"] = path.resolve(__dirname);
- return config;
- },
- };
- {
- "compilerOptions": {
- "baseUrl": ".",
- "paths": {
- "@/*": [ "src/*"]
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。