小白学 Webpack之Resolve 配置

webpack Resolve 省略后缀,识别多后缀

webpack.config.js

  resolve:{
    extensions:[".ts",".js",".json",".css",".less",".scss"]
  },

原本引入

require('../css/base.css');

现在可以

require('../css/base');

webpack Resolve 别名路径

 resolve:{
    extensions:[".ts",".js",".json",".css",".less",".scss"],
    alias: {
      "css": path.resolve(__dirname,"./src/css"),
      "js":path.resolve(__dirname,"./src/js")
    }

  },

这样原本

require('../css/base.css');

就可以改成

require('css/base.css');或require('$css/base.css');

webpack Resolve 解析模块目录

 resolve:{
    modules: [
      path.resolve(__dirname,"./node_modules"),//可多个定义位置
    ]
  },

这样就可以自动找到模块位置。

评论区 (0)

没有记录
支持 markdown,图片截图粘贴拖拽都可以自动上传。