javascript - webpack中alias配置中的“@”是什么意思?
PHP中文网
PHP中文网 2017-04-17 16:34:12
0
2
531
 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中文网

认证0级讲师

reply all(2)
巴扎黑

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')】路径的作用。
洪涛

Similar problems can be solved by looking at the official documents

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template