【问题标题】:webpack resolve alias for styles(stylus) as well in vue.js componentswebpack 在 vue.js 组件中解析样式(stylus)的别名
【发布时间】:2017-06-16 21:43:07
【问题描述】:

在我的webpack.config.jsfile 中的vue.jsproject 上,我确实有这个:

///...,
resolve: {
  extensions: ['.js', '.vue', '.json'],
  alias: {
    'vue$': 'vue/dist/vue.common.js',
    'assets': path.resolve(__dirname, './src/assets'),
    'components': path.resolve(__dirname, './src/components')
  }
},
// ....

这允许我在任何 Vue component 中使用其他组件,例如:

import 'component/path/to/MyComponent'

不必怀疑我在组件树中的位置。

我希望你拥有与styles 相同的容量,尤其是使用`stylus``

假设我有 stylus file' insrc/assets/funcs.styl:

add(a)
  a + a

还有一个组件,比如src/components/a/very/long/path/MyComponent.vue:

<template>
  <div id="my-component">
    <h1>{{ msg }}</h1>
  </div
</template>

<script>

export default {
  name: 'my-component',
  data () {
    return {
      msg: 'A title'
    }
  }
}
</script>

<style lang="stylus" scoped>
@import "../../../../../../assets/funcs.styl"

h1
 margin add(30px)

</style>

我希望能够替换这一行

@import "../../../../../../assets/funcs.styl"

通过这个

@import "assets/funcs"

使用适用于 js 文件的 webpack 解析和别名功能。 这将避免在大型项目中很难找到我在深层组件中可能需要的手写笔混合和功能的错误。

他们有办法这样做吗?
它必须是功能请求吗?在webpack?在vue-style-loader?在stylus-loader?

任何精度都将不胜感激;-)

Seb

【问题讨论】:

    标签: webpack vue.js stylus webpack-style-loader


    【解决方案1】:

    你应该使用

    @import '~assets/funcs';

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-27
      • 2020-07-28
      • 2018-11-01
      • 2017-06-30
      • 1970-01-01
      • 1970-01-01
      • 2017-02-21
      • 2017-02-05
      相关资源
      最近更新 更多