如何在gulp-sass中编译地图数组?

问题描述 投票:0回答:1

我正在尝试使用map数组编译.scss文件,但在gulp-sass中有错误。如何在scss文件中编译数组?

这是我使用Redux Framework开发的新WordPress主题。我尝试在主题中实现调色板,并为一个调色板编写了许多类。所以我想用SASS进行一些自动化。

$violet: ( 
  first   : #ffffff,
  second  : #171717,
  third   : #fdec00,
  fourth  : #400061,
  fifth   : #fff88f,
  sixth   : #ffd600,
  seventh : #121212
);

@each $class, $color in $violet {
  .violet_#{$class}_bg {
    background-color: $color;
  }
}

我在gulp-sass中有错误^

Error: (first: #ffffff, second: #171717, third: #fdec00, fourth: #400061, fifth: #fff88f, sixth: #ffd600, seventh: #121212) isn't a valid CSS value.
        on line 23 of sass/theme/_theme_variables.scss
        from line 11 of sass/theme.scss
>> $violet: ( 

   ---------^

    at options.error (/home/yegor/lampstack-7.1.25-0/apache2/htdocs/akimovdesign/wp-content/themes/understrap/node_modules/node-sass/lib/index.js:291:26)
  status: 1,
  file:
   '/home/yegor/lampstack-7.1.25-0/apache2/htdocs/akimovdesign/wp-content/themes/understrap/sass/theme/_theme_variables.scss',
  line: 23,
  column: 10,
  message:
   'sass/theme/_theme_variables.scss\nError: (first: #ffffff, second: #171717, third: #fdec00, fourth: #400061, fifth: #fff88f, sixth: #ffd600, seventh: #121212) isn\'t a valid CSS value.\n        on line 23 of sass/theme/_theme_variables.scss\n        from line 11 of sass/theme.scss\n>> $violet: ( \n\n   ---------^\n',
  formatted:
   'Error: (first: #ffffff, second: #171717, third: #fdec00, fourth: #400061, fifth: #fff88f, sixth: #ffd600, seventh: #121212) isn\'t a valid CSS value.\n        on line 23 of sass/theme/_theme_variables.scss\n        from line 11 of sass/theme.scss\n>> $violet: ( \n\n   ---------^\n',
  messageFormatted:
   '\u001b[4msass/theme/_theme_variables.scss\u001b[24m\nError: (first: #ffffff, second: #171717, third: #fdec00, fourth: #400061, fifth: #fff88f, sixth: #ffd600, seventh: #121212) isn\'t a valid CSS value.\n        on line 23 of sass/theme/_theme_variables.scss\n        from line 11 of sass/theme.scss\n>> $violet: ( \n\n   ---------^\n',
  messageOriginal:
   '(first: #ffffff, second: #171717, third: #fdec00, fourth: #400061, fifth: #fff88f, sixth: #ffd600, seventh: #121212) isn\'t a valid CSS value.',
  relativePath: 'sass/theme/_theme_variables.scss',
  name: 'Error',
  stack:
   'Error: sass/theme/_theme_variables.scss\nError: (first: #ffffff, second: #171717, third: #fdec00, fourth: #400061, fifth: #fff88f, sixth: #ffd600, seventh: #121212) isn\'t a valid CSS value.\n        on line 23 of sass/theme/_theme_variables.scss\n        from line 11 of sass/theme.scss\n>> $violet: ( \n\n   ---------^\n\n    at options.error (/home/yegor/lampstack-7.1.25-0/apache2/htdocs/akimovdesign/wp-content/themes/understrap/node_modules/node-sass/lib/index.js:291:26)',
  __safety: undefined,
  _stack: undefined,
  plugin: 'gulp-sass',
  showProperties: true,
  showStack: false }

我期待输出:

.violet_first_bg {
  background-color: #ffffff;
}
.violet_second_bg {
  background-color: #171717;
}

and so on...
css wordpress sass gulp gulp-sass
1个回答
0
投票
$bg: (
    primary     : $primary-colour,
    secondary   : $secondary-colour,
    lightgrey   : $lightgrey,   
    white       : $white,
    brown       : $brown,
);


@each $name, $value in $bg {
    .bg--colour_#{"" + $name} {
        background: $value;
    }
}

尝试以下操作,但当然将变量更改为您的项目。让我知道结果。

© www.soinside.com 2019 - 2024. All rights reserved.