resolve
howcode 2022-07-18 0 webpack
# 别名
const path = require("path")
resolve:{
alias:{
"@":path.resolve(__dirname,'./src')
}
}
1
2
3
4
5
6
7
2
3
4
5
6
7
# 读取拓展名
很多时候我们引入文件的时候不带拓展名,例如
const math = require("math");
1
试着思考下
如果根目录下存在 math.js 和 math.json 的两个文件,webpack 是如何选择引入哪个文件的呢?
其实,在 webpack 下有个 extensions 的配置,默认情况下是优先引入 js 文件的,现在我们手动去更改该配置
const path = require("path")
resolve:{
alias:{
"@":path.resolve(__dirname,'./src')
},
extensions:['json','js','vue'] // 此时引入的文件优先级为:json > js >vue
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
评论
- 表情
——暂无评论——