简体   繁体   English

如何在没有 gulp 和 laravel-elixir 的情况下编译 sass [修复]

[英]How to compile sass without gulp and laravel-elixir [ FIX ]

If You get an error like this :如果你得到这样的错误这样

错误

Then you are in the right place :)那么你来对地方了:)

Firstly first you have to delete the node_modules folder from your project.首先,您必须从项目中删除 node_modules 文件夹。 To do this, type these commands :为此,请键入以下命令:

Please note, copy the module name before deleting the package.json :)请注意,在删除 package.json 之前复制模块名称:)

  1. rm -rf node_modules rm -rf node_modules
  2. rm -rf package-lock.json rm -rf 包-lock.json
  3. rm -rf package.json rm -rf 包.json
  4. npm cache clean npm 缓存清理

Now you will need a new package.json by doing this you need this command:现在你将需要一个新的 package.json 这样做你需要这个命令:

  • npm init初始化

hit enter until the command-line comes back.按 Enter 直到命令行返回。

Now you need to install Node-Sass to do this, type this command:现在您需要安装Node-Sass来执行此操作,输入以下命令:

  • npm install node-sass npm 安装 node-sass

if there's a problem with permissions try it with sudo, like this:如果权限有问题,请尝试使用 sudo,如下所示:

  • sudo npm install node-sass须藤 npm 安装 node-sass

After installing Node-sass you need to write Node-sass command, go to the package.json file and you will see something like this:安装Node-sass 后,你需要编写Node-sass命令,进入 package.json 文件,你会看到如下内容:

{
  "name": "blog",
  "version": "1.0.0",
  "description": "Bla Bla Bla Bla ...",
  "main": "gulpfile.js",
  "directories": {
    "test": "tests"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bootstrap": "^4.4.1",
    "jquery": "^3.4.1",
    "node-sass": "^4.13.1"
  }
}

In the scripts section add an scss command, under the test command, like this:在脚本部分添加一个 scss 命令,在 test 命令下,如下所示:

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "scss": "node-sass resources/assets/sass -o public/css"
}

you can use --watch option, like this:您可以使用 --watch 选项,如下所示:

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "scss": "node-sass --watch resources/assets/sass -o public/css"
}

Which means to watch a directory or file if there's a change, in other terms, it will compile all .scss files every time you hit CTRL + S or CMD + S .这意味着如果有更改,则监视目录或文件,换句话说,每次点击CTRL + SCMD + S时,它都会编译所有 .scss 文件。

And Finally, run the script:最后,运行脚本:

  • npm run scss npm 运行 scss

Many thanks to Zviad Sichinava .非常感谢Zviad Sichinava

Learn More about node-sass .了解有关node-sass 的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM