在vue文件中,要引入相应的样式,经常会用到
@import "~common/stylus/mixin"
这种写法,为什么会用到~
?查看了stylus-loader
,发现这句话 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
才能通过~别名
来实现查找相应的文件。