我想替换sass配置文件中的几个sass变量值。例如,我想替换变量"$file_global“=”new“的值;
我想使用“咕噜
我的项目目录结构:
grep/
/node_modules/
package.json
Gruntfile.js
src/
my-styles.scssmy-styles.scss 代码:
$file_global: "old";Gruntfile.js 代码:
module.exports = function(grunt){
pkg: grunt.file.readJSON('package.json'),
grunt.initConfig({
'sass-replace': {
files: { // File Options
src: 'src/my-styles.scss',
dest: 'dest/my-styles.scss'
},
options: {
variables: [
{
name: 'file_global',
to: 'new'
}
]
}
}
});
grunt.loadNpmTasks('grunt-sass-replace');
grunt.registerTask('default', ['sass-replace']);
};package.json代码:
{
"name": "grep",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "KJ",
"license": "ISC",
"devDependencies": {
"grunt": "^1.0.4",
"grunt-sass-replace": "^0.1.18",
"npm-check-updates": "^3.1.9"
}
}我更新了“文件”,但它仍然给我带来了各种错误。下面是我尝试过的选项和生成的错误。
第一次尝试
// Option First :
files: {
'dest/my-styles.scss': 'src/my-styles.scss'
},
ERROR :
C:\wamp64\www\GREP>grunt
>> Tasks directory "C:\wamp64\www\GREP\node_modules\grunt-sass-replace\node_modules\grunt-string-replace\tasks" not found.
Running "sass-replace:files" (sass-replace) task
Warning: no files passed. Use --force to continue..
Aborted due to warnings.第二次尝试:
// Option Second :
files: [
{
src: 'src/my-styles.scss',
dest: 'dest/my-styles.scss'
}
],
ERROR :
C:\wamp64\www\GREP>grunt
>> Tasks directory "C:\wamp64\www\GREP\node_modules\grunt-sass-replace\node_modules\grunt-string-replace\tasks" not found.
Running "sass-replace:files" (sass-replace) task
Warning: pattern.indexOf is not a function Use --force to continue.
Aborted due to warnings.最后一次尝试:
// Option Third :
files: {
src: 'src/my-styles.scss',
dest: 'dest/my-styles.scss'
},
ERROR :
C:\wamp64\www\GREP>grunt
>> Tasks directory "C:\wamp64\www\GREP\node_modules\grunt-sass-replace\node_modules\grunt-string-replace\tasks" not found.
Running "sass-replace:files" (sass-replace) task
>> [1] scss files found in [1] passed files.
>> replacements resolved successfully.
running string-replace task.
Warning: Task "string-replace:sass" not found. Use --force to continue.
Aborted due to warnings.任何人都知道如何解决这个错误,或者任何其他可以完成这种工作的程序包.。
发布于 2019-05-19 08:09:44
这个软件包是3年前更新的,也使用了grunt ~0.4.5。我不能帮你做这件事,不过看看https://www.npmjs.com/package/grunt-sass-replace-values的“咕噜-沙司-替换-值”。这个包是一年前更新的,并进行了修补。
npm安装grunt-sass-替换-值-保存-dev
查看Github上的下列问题:https://github.com/eliranmal/grunt-sass-replace/issues/1
解释:
错误原因:
解决方案:
在项目根目录下,转到下面的目录:
node_modules/grunt-sass-replace/tasks在上面的目录中,查找一个文件名"sass-replace.js"
只需使用任何文本编辑器打开文件,并编辑到依赖项的路径。
grunt.task.loadTasks(path.resolve(__dirname, '../node_modules/grunt-string-replace/tasks'));在您的示例中,如下所示:
grunt.task.loadTasks(path.resolve(__dirname, '../../../node_modules/grunt-string-replace/tasks'));我希望这能解决你的问题。如果不使用另一个包,或者使用旧的节点和grunt(0.4.5)版本。
https://stackoverflow.com/questions/56205785
复制相似问题