webpack 相对路径配置

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'common/stylus/index.styl'
Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

 ERROR  Failed to compile with 1 errors                                                                                                                 14:03:25
This dependency was not found:

* common/stylus/index.styl in ./src/main.js

To install it, you can run: npm install --save common/stylus/index.styl

解决方案:

webpack.base.conf.js

  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
      'common': resolve('src/common')
    }
  },

可以看到他本身有@来进行相对路径的匹配,如果想再省略@进行进一步,可以在alias进行配置。 

猜你喜欢

转载自blog.csdn.net/qq_37021554/article/details/89881376