search

Home  >  Q&A  >  body text

javascript - webpack中alias配置中的“@”是什么意思?

 output: {
    path: config.build.assetsRoot,
    filename: '[name].js',
    publicPath: process.env.NODE_ENV === 'production'
      ? config.build.assetsPublicPath
      : config.dev.assetsPublicPath
  },
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    -------------@是什么意思----------------
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src')
    }
    -------------------------------
  },
PHP中文网PHP中文网2872 days ago575

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 16:36:12

    It’s just an alias.
    The alias is set here to reduce the complexity of the path for subsequent references.

    //例如
    src
     - components
       - a.vue
     - router
       - home
         - index.vue
    
    
    index.vue 里,正常引用 A 组件:
    
    import A from '../../components/a.vue'
    
    如果设置了 alias 后。
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src')
    }
    
    引用的地方路径就可以这样了
    
    import A from '@/components/a.vue'
    
    这里的 @ 就起到了【resolve('src')】路径的作用。
    

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 16:36:12

    Similar problems can be solved by looking at the official documents

    reply
    0
  • Cancelreply