浏览代码

WIP getting prod working with minicss webpack plugin

d98762625 6 年之前
父节点
当前提交
d22eac9f35
共有 2 个文件被更改,包括 26 次插入8 次删除
  1. 2 1
      Gruntfile.js
  2. 24 7
      src/web/RecipeWaiter.mjs

+ 2 - 1
Gruntfile.js

@@ -194,7 +194,8 @@ module.exports = function (grunt) {
                         sitemap: "./src/web/static/sitemap.js"
                         sitemap: "./src/web/static/sitemap.js"
                     }, moduleEntryPoints),
                     }, moduleEntryPoints),
                     output: {
                     output: {
-                        path: __dirname + "/build/prod"
+                        path: __dirname + "/build/prod",
+                        globalObject: "this"
                     },
                     },
                     resolve: {
                     resolve: {
                         alias: {
                         alias: {

+ 24 - 7
src/web/RecipeWaiter.mjs

@@ -8,6 +8,8 @@ import HTMLOperation from "./HTMLOperation";
 import Sortable from "sortablejs";
 import Sortable from "sortablejs";
 import Utils from "../core/Utils";
 import Utils from "../core/Utils";
 
 
+/*eslint no-console: ["off"] */
+
 
 
 /**
 /**
  * Waiter to handle events related to the recipe.
  * Waiter to handle events related to the recipe.
@@ -561,20 +563,35 @@ class RecipeWaiter {
             this.ingredientChildRuleID = null;
             this.ingredientChildRuleID = null;
 
 
             // Find relevant rules in the stylesheet
             // Find relevant rules in the stylesheet
-            for (const i in document.styleSheets[0].cssRules) {
-                if (document.styleSheets[0].cssRules[i].selectorText === ".ingredients") {
-                    this.ingredientRuleID = i;
-                }
-                if (document.styleSheets[0].cssRules[i].selectorText === ".ingredients > div") {
-                    this.ingredientChildRuleID = i;
+            // try {
+            if (document.styleSheets[0].hasOwnProperty("cssRules")) {
+                for (const i in document.styleSheets[0].cssRules) {
+                    if (document.styleSheets[0].cssRules[i].selectorText === ".ingredients") {
+                        this.ingredientRuleID = i;
+                    }
+                    if (document.styleSheets[0].cssRules[i].selectorText === ".ingredients > div") {
+                        this.ingredientChildRuleID = i;
+                    }
                 }
                 }
             }
             }
+            // } catch (e) {
+            //     console.log(e.constructor);
+            //     console.warn("Can't read the css rules of: " + document.styleSheets[0], e);
+            // }
         }
         }
 
 
         if (!this.ingredientRuleID || !this.ingredientChildRuleID) return;
         if (!this.ingredientRuleID || !this.ingredientChildRuleID) return;
+        let ingredientRule, ingredientChildRule;
 
 
-        const ingredientRule = document.styleSheets[0].cssRules[this.ingredientRuleID],
+        // Chrome 64+
+        // try {
+        if (document.styleSheets[0].hasOwnProperty("cssRules")) {
+            ingredientRule = document.styleSheets[0].cssRules[this.ingredientRuleID];
             ingredientChildRule = document.styleSheets[0].cssRules[this.ingredientChildRuleID];
             ingredientChildRule = document.styleSheets[0].cssRules[this.ingredientChildRuleID];
+        }
+        // } catch (e) {
+        //     console.warn("Can't read the css rules of: " + document.styleSheets[0], e);
+        // }
 
 
         if (recList.clientWidth < 450) {
         if (recList.clientWidth < 450) {
             ingredientRule.style.gridTemplateColumns = "auto auto";
             ingredientRule.style.gridTemplateColumns = "auto auto";