zl程序教程

您现在的位置是:首页 >  其他

当前栏目

next 引入路径修改为@

2023-04-18 13:12:05 时间

当前项目结构预览

  • 正常效果
  • 想要达成的效果
  • 新建 jsconfig.json 写入如下代码
{
    "compilerOptions": {
      "baseUrl": ".",
      "paths": {
        "@/*": [
          "./*"
        ],
      }
    }
  }
  • 再新建 next.config.js 写入如下代码
const path = require("path");
module.exports = {
  webpack: (config) => {
    config.resolve.alias["@"] = path.resolve(__dirname);
    return config;
  },
};
  • OK,完成了,牛逼PLUS