Node / npm:使用 node-sass 编译 scss 时找不到要导入的文件
Node / npm : File to import not found when compiling scss with node-sass
我正在尝试使用 package.json
中的以下脚本将 sass
编译为 node-sass
:
"node-sass": "node-sass --output-style compressed 'src/scss/styles.scss' 'dist/css/bundle.min.css'",
我的styles.scss
:
@import "bourbon";
@import "neat";
body {background: red;}
但是当我 运行 npm run node-sass
我得到以下错误:
"formatted": "Error: File to import not found or unreadable: bourbon\n Parent style sheet: /Users/deangibson/Desktop/personal_site/src/scss/styles.scss\n on line 1 of src/scss/styles.scss\n>> @import \"bourbon\";\n ^\n",
"message": "File to import not found or unreadable: bourbon\nParent style sheet: /Users/deangibson/Desktop/personal_site/src/scss/styles.scss",
"column": 1,
"line": 1,
"file": "/Users/deangibson/Desktop/personal_site/src/scss/styles.scss",
"status": 1
}
我的项目结构如下所示:
节点不应该在涉及依赖项时自动检查 node_modules 吗?我不明白我在这里做错了什么...
是的,node
会自动在 node_modules
的 JavaScript 文件中查找您 require
的内容。但是,您正在执行命令行应用程序 node-sass
,但它并没有这样做。
您可以像这样向 node-sass
命令行应用程序提供 --include-path(多行以提高可读性,在 package.json
中需要单行)
node-sass
--output-style compressed
--include-path node_modules/bourbon/app/assets/stylesheets/
--include-path node_modules/bourbon-neat/app/assets/stylesheets/
'src/scss/styles.scss'
'dist/css/bundle.min.css'
如果你写一个render JavaScript file that is executed with node
you can setup the includePath
by merging the arrays exported by the bourbon
modules when you require them.
我正在尝试使用 package.json
中的以下脚本将 sass
编译为 node-sass
:
"node-sass": "node-sass --output-style compressed 'src/scss/styles.scss' 'dist/css/bundle.min.css'",
我的styles.scss
:
@import "bourbon";
@import "neat";
body {background: red;}
但是当我 运行 npm run node-sass
我得到以下错误:
"formatted": "Error: File to import not found or unreadable: bourbon\n Parent style sheet: /Users/deangibson/Desktop/personal_site/src/scss/styles.scss\n on line 1 of src/scss/styles.scss\n>> @import \"bourbon\";\n ^\n",
"message": "File to import not found or unreadable: bourbon\nParent style sheet: /Users/deangibson/Desktop/personal_site/src/scss/styles.scss",
"column": 1,
"line": 1,
"file": "/Users/deangibson/Desktop/personal_site/src/scss/styles.scss",
"status": 1
}
我的项目结构如下所示:
节点不应该在涉及依赖项时自动检查 node_modules 吗?我不明白我在这里做错了什么...
是的,node
会自动在 node_modules
的 JavaScript 文件中查找您 require
的内容。但是,您正在执行命令行应用程序 node-sass
,但它并没有这样做。
您可以像这样向 node-sass
命令行应用程序提供 --include-path(多行以提高可读性,在 package.json
中需要单行)
node-sass
--output-style compressed
--include-path node_modules/bourbon/app/assets/stylesheets/
--include-path node_modules/bourbon-neat/app/assets/stylesheets/
'src/scss/styles.scss'
'dist/css/bundle.min.css'
如果你写一个render JavaScript file that is executed with node
you can setup the includePath
by merging the arrays exported by the bourbon
modules when you require them.