今天在初始化項目中,出現了一個奇怪的情況:明明路徑是對的,但是編譯的時候,一直報“This dependency was not found”的錯。
代碼如下:
import Vue from 'vue'
import App from './App'
import router from './router'
import 'common/stylus/index.styl'
/* eslint-disable no-new */
new Vue({
el: '#app',
render: h => h(App)
})
控制台一直報錯,表示無法找到common/stylus/index.styl
,然而,路徑是通過ide補全填寫的,不可能出現錯誤,那又是為什么?
多次測試發現,Vue中的引入文件時,需要通過./
通知編譯器是在當前路徑,不然的話,第一個文件夾名會被認為是webpack配置的alias
(別名)。
所以,正確引入index.styl
的方式是:
import Vue from 'vue'
import App from './App'
import router from './router'
import './common/stylus/index.styl' // 添加./避免編譯器認為是別名
/* eslint-disable no-new */
new Vue({
el: '#app',
render: h => h(App)
})