下载 hard-source-webpack-plugin
- yarn add hard-source-webpack-plugin -D
const hardPlugin = require("hard-source-webpack-plugin")
const { resolve } = require("path")
module.exports = {
configureWebpack: {
plugins: [
new hardPlugin({ // 缓存启动的文件,提升启动速度
cacheDirectory: resolve(__dirname, "cache")
})
],
resolve: {
alias: {
"@c": resolve(__dirname, "src/components"),
}
}
}
}
- 可以看到项目中多个cache文件,这样就可以提升项目的启动速度了
起alias别名
- 但是我们发现给项目起别名之后,输入@c并没有提示,我们在根目录下新建jsconfig.json文件
- jsconfig.json
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@c/*": ["./components/*"],
}
},
"exclude": ["node_modules", "cache"]
}
- 重新启动项目,我们发现就可以找到这个@c/下边的文件了