【问题标题】:wierd! require('stylus') in .vue file Failed奇怪! .vue 文件中的 require('stylus') 失败
【发布时间】:2017-06-09 15:39:22
【问题描述】:

我尝试在test.vue 文件中使用手写笔

let stylus = require('stylus')
console.log(stylus)

但是失败了。

This dependency was not found:
* fs in ./~/.0.54.5@stylus/lib/utils.js, ./~/.0.54.5@stylus/lib/middleware.js and 12 others
To install it, you can run: npm install --save fs
This relative module was not found:
* ./lib-cov/stylus in ./~/.0.54.5@stylus/index.js

我触摸了一个新的test.js 文件,并在其中添加了require('stylus'),没关系。 太奇怪了。

"vue": "^2.3.3",
"stylus": "^0.54.5",

任何帮助将不胜感激,谢谢。

【问题讨论】:

  • 尝试在 webpack 配置文件中添加 node: { fs: 'empty' }。
  • @qkr 我在webpack.base.conf.js中添加了,但是不行。
  • 如果你想在.vue文件中使用stylus,你需要webpack的loader,它叫做stylus-loader
  • @BelminBedak 我使用 npm install stylus-loader 并在 webpack.base.conf.js 中添加 {test: /\.styl$/,loader: 'style-loader!css-loader!stylus-loader'}。还是不行。
  • 我认为您不必在 webpack 文件中明确将其作为规则包含在内 - 只需在 style 文件的 style 部分添加 lang="stylus" 属性即可。

标签: vue.js require vue-component stylus


【解决方案1】:

Stylus javascript API 无法在浏览器中运行,因为它依赖于 NodeJs 的 fs 模块: https://nodejs.org/docs/v0.3.1/api/fs.html

【讨论】:

    猜你喜欢
    • 2013-12-15
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    • 2016-06-29
    • 2015-01-16
    相关资源
    最近更新 更多