@import '~common/stylus/mixin'中 ~ 的做用

在vue文件中,要引入相應的樣式,常常會用到
@import "~common/stylus/mixin"這種寫法,爲何會用到~?查看了stylus-loader文檔,發現這句話vue

It also lets you load a stylus file from a package installed in node_modules or if you add a modulesDirectories, like modulesDirectories: ['node_modules', 'web_modules', 'bower_components'] option you could load from a folder like bower_components. To load files from a relative path leave off the ~ and @import 'relative-styles/my-styles'; it.

結合本人作的測試,發現這個~和webpack配置文件中alias有關,只有在webpack配置文件中配置了alias,設置了相應的別名路徑,@import才能經過~別名來實現查找相應的文件。node

相關文章
相關標籤/搜索