0

In my project, I created a new file header.vue in src/components/header/. The code is

<template>
  <div class="header">
    I am header!!
  </div>
</template>
<script type="text/ecmascript-6">
  export default({})
</script>
<style lang="stylus" rel="stylesheet/stylus">
</style>

I want to use it in App.vue, Here is my code:

<template>
  <div id="app">
    <header></header>
  </div>
</template>

<script>
   import header from './components/header/header.vue'

  export default {
    components: {
      header: header
    }
  }
</script>

<style>
#app {
 .....
}

But i have got error in console:

This dependency was not found:

* !!vue-style-loader!css-loader?{"sourceMap":true}!../../../node_modules/vue- 
 loader/lib/style-compiler/index?{"vue":true,"id":"data-v- 
 12835cef","scoped":false,"hasInlineConfig":false}!stylus-loader? 
 {"sourceMap":true}!../../../node_modules/vue-loader/lib/selector? 
 type=styles&index=0!./header.vue in ./src/components/header/header.vue

I had found that ""css-loader": "^0.28.0"," is in package.jsaon already, So I added

"stylus-loader": "^2.1.1",

into package.json. and restarted "npm run dev"

But unlucky, it doesn't work, it failed again. Who can help me ?

3
  • did you add the rule for stylus in your webpack config? Commented Jul 12, 2018 at 8:34
  • Did you generate the vue project using vue-cli? If yes the which version of vue-cli? Commented Jul 12, 2018 at 8:41
  • @VamsiKrishna, yes, I used "npm install -g vue-cli" and "vue init webpack sell". The version of vue is 2.9.6 Commented Jul 12, 2018 at 8:44

1 Answer 1

3

1: Add stylus-loader as a dev dependency by executing the following command

npm install stylus stylus-loader --save-dev

2: Add the stylus rule to the webpack config

Locate the webpack.base.conf.js in the build folder and add the following rule

module: {
  rules: [
    {
      test: /\.styl$/,
      loader: ['style-loader', 'css-loader', 'stylus-loader']
    }
  ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.