daisyui 2.3.6 → 2.3.7-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.js CHANGED
@@ -10,8 +10,6 @@ let utilitiesUnstyled = require("../dist/utilities-unstyled");
10
10
  let utilitiesStyled = require("../dist/utilities-styled");
11
11
  const themes = require("./colors/themes");
12
12
  const colorFunctions = require("./colors/functions");
13
- const postcssJs = require('postcss-js');
14
- // const postcssPrefix = require('postcss-prefixer');
15
13
 
16
14
  const mainFunction = ({ addBase, addComponents, addUtilities, config }) => {
17
15
  let diasyuiIncludedItems = [];
@@ -65,12 +63,24 @@ const mainFunction = ({ addBase, addComponents, addUtilities, config }) => {
65
63
  }
66
64
 
67
65
  // add prefix to class names if specified
68
- const prefix = config('daisyui.prefix');
66
+ const prefix = config("daisyui.prefix")
67
+ let postcssJs, postcssPrefix
69
68
  if (prefix) {
70
- // file = postcssJs.sync(postcssPrefix({
71
- // prefix: prefix,
72
- // ignore: []
73
- // }))(file)
69
+ try {
70
+ postcssJs = require("postcss-js")
71
+ postcssPrefix = require("postcss-prefixer")
72
+ } catch (error) {
73
+ if (logs) {
74
+ console.error(`Error occurred and prevent applying the "prefix" option:`, error)
75
+ }
76
+ }
77
+ }
78
+ const shouldApplyPrefix = prefix && postcssPrefix && postcssJs;
79
+ if (shouldApplyPrefix) {
80
+ file = postcssJs.sync(postcssPrefix({
81
+ prefix: prefix,
82
+ ignore: []
83
+ }))(file)
74
84
  }
75
85
 
76
86
  addComponents(file);
@@ -83,18 +93,18 @@ const mainFunction = ({ addBase, addComponents, addUtilities, config }) => {
83
93
  // inject @utilities style needed by components
84
94
  if (config("daisyui.utils") != false) {
85
95
  addComponents(utilities, { variants: ["responsive"] });
86
- if (prefix) {
87
- // utilitiesUnstyled = postcssJs.sync(postcssPrefix({
88
- // prefix: prefix,
89
- // ignore: []
90
- // }))(utilitiesUnstyled)
96
+ if (shouldApplyPrefix) {
97
+ utilitiesUnstyled = postcssJs.sync(postcssPrefix({
98
+ prefix: prefix,
99
+ ignore: []
100
+ }))(utilitiesUnstyled)
91
101
  }
92
102
  addComponents(utilitiesUnstyled, { variants: ["responsive"] });
93
- if (prefix) {
94
- // utilitiesStyled = postcssJs.sync(postcssPrefix({
95
- // prefix: prefix,
96
- // ignore: []
97
- // }))(utilitiesStyled)
103
+ if (shouldApplyPrefix) {
104
+ utilitiesStyled = postcssJs.sync(postcssPrefix({
105
+ prefix: prefix,
106
+ ignore: []
107
+ }))(utilitiesStyled)
98
108
  }
99
109
  addComponents(utilitiesStyled, { variants: ["responsive"] });
100
110
  diasyuiIncludedItems.push("utilities");