Задать вопрос
@RaDir

Почему не работает this в объекте?

Всем привет!

Делаю сборку проекта на node и gulp.
Файл config/styles.js:
module.exports = {
    theme: {
        skins: {
            blue: "blue.css",
            brown: "brown.css",
            dark_cyan: "dark_cyan.css",
            dark_gray: "dark_gray.css",
            dark_red: "dark_red.css",
            green: "green.css",
            light_blue: "light_blue.css",
            light_green: "light_green.css",
            orange: "orange.css",
            pink: "pink.css",
            purple: "purple.css",
            red: "red.css",
            yellow: "yellow.css"
        },
        current: {
            skin: this.theme.skins.blue
        }
    },
    customization: {
        src: "src/styles/*",
        dist: "styles"
    },
    vendor: {
        theme: {
            bootstrap: "src/vendor/theme/html/bootstrap/css/bootstrap.css",
            "font-awesome": "src/vendor/theme/html/fonts/font-awesome/css/font-awesome.css",
            fontello: "src/vendor/theme/html/fonts/fontello/css/fontello.css",
            "rs-plugin-settings": "src/vendor/theme/html/plugins/rs-plugin/css/settings.css",
            "rs-plugin-extralayers": "src/vendor/theme/html/plugins/rs-plugin/css/extralayers.css",
            "magnific-popup": "src/vendor/theme/html/plugins/magnific-popup/magnific-popup.css",
            animations: "src/vendor/theme/html/css/animations.css",
            "owl-carousel": "src/vendor/theme/html/plugins/owl-carousel/owl.carousel.css",
            "core-style": "src/vendor/theme/html/css/style.css",
            //skin: "src/vendor/theme/html/css/skins/" + this.theme.current.skin
        }
    },
    templates: {
        lp_v1: [
            "bootstrap", "font-awesome", "fontello", "rs-plugin-settings", "rs-plugin-extralayers", "magnific-popup",
            "animations", "owl-carousel", "core-style", "skin"
        ]
    }
};


gulpfile.js:
var gulp = require('gulp');
var requireDir = require('require-dir');
var config = requireDir('./config');

gulp.task('console', function () {
    console.log(config.styles);
});


Результат команды gulp console: TypeError: Cannot read property 'skins' of undefined

Помогите, объясните, пожалуйста, в чем ошибка?
  • Вопрос задан
  • 243 просмотра
Подписаться 1 Оценить 3 комментария
Решения вопроса 1
@Aves
Можно примерно так:
const skins = {
  blue: "blue.css",
  brown: "brown.css",
  dark_cyan: "dark_cyan.css",
  dark_gray: "dark_gray.css",
  dark_red: "dark_red.css",
  green: "green.css",
  light_blue: "light_blue.css",
  light_green: "light_green.css",
  orange: "orange.css",
  pink: "pink.css",
  purple: "purple.css",
  red: "red.css",
  yellow: "yellow.css"
};

const theme = {
  skins,
  current: {
    skin: skins.blue
  }
};

module.exports = {
  theme,
  customization: {
    src: "src/styles/*",
    dist: "styles"
  },
  vendor: {
    theme: {
      bootstrap: "src/vendor/theme/html/bootstrap/css/bootstrap.css",
      "font-awesome": "src/vendor/theme/html/fonts/font-awesome/css/font-awesome.css",
      fontello: "src/vendor/theme/html/fonts/fontello/css/fontello.css",
      "rs-plugin-settings": "src/vendor/theme/html/plugins/rs-plugin/css/settings.css",
      "rs-plugin-extralayers": "src/vendor/theme/html/plugins/rs-plugin/css/extralayers.css",
      "magnific-popup": "src/vendor/theme/html/plugins/magnific-popup/magnific-popup.css",
      animations: "src/vendor/theme/html/css/animations.css",
      "owl-carousel": "src/vendor/theme/html/plugins/owl-carousel/owl.carousel.css",
      "core-style": "src/vendor/theme/html/css/style.css",
      skin: "src/vendor/theme/html/css/skins/" + theme.current.skin
    }
  },
  templates: {
    lp_v1: [
      "bootstrap", "font-awesome", "fontello", "rs-plugin-settings", "rs-plugin-extralayers", "magnific-popup",
      "animations", "owl-carousel", "core-style", "skin"
    ]
  }
};
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы
Rocket Смоленск
от 80 000 до 130 000 ₽
div. Ставрополь
от 40 000 до 90 000 ₽
Wanted. Санкт-Петербург
До 220 000 ₽
18 дек. 2024, в 11:03
5000 руб./за проект
18 дек. 2024, в 10:44
130000 руб./за проект
18 дек. 2024, в 10:02
7000 руб./за проект