与 Laravel Jetstream 一起使用时,Tailwind Colors 无法编译
Tailwind Colors not compiling when used with Laravel Jetstream
我有一个 Laravel Jetstream 安装并使用 Tailwind CSS 但是在使用 Tailwind 组件时默认颜色不起作用。
我只想使用默认颜色,还不想自定义。
tailwind.config.js
const defaultTheme = require('tailwindcss/defaultTheme');
module.exports = {
mode: 'jit',
purge: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./vendor/laravel/jetstream/**/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
theme: {
extend: {
fontFamily: {
sans: ['Nunito', ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [require('@tailwindcss/forms'), require('@tailwindcss/typography')],
};
Jetstream 随 Tailwind 2.2.2 一起安装,该版本会出现此问题。我已尝试降级到 2.0.2,这是已知对我有用的最新版本,但也出现了问题
当使用相同的 HTML 代码时,在使用 tailwind 2.0.2 安装的 Laravel Breeze 中使用时可以正常工作。
例子html
<div class="flex-shrink-0 flex items-center justify-center w-16 bg-pink-600 text-white text-sm font-medium rounded-l-md">
</div>
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"@tailwindcss/forms": "^0.3.1",
"@tailwindcss/typography": "^0.4.0",
"alpinejs": "^3.0.6",
"axios": "^0.21",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"postcss-import": "^14.0.1",
"tailwindcss": "^2.2.2"
},
"dependencies": {
"daisyui": "^1.13.2"
}
}
在上面的示例中,bg-pink-600 未呈现。
您必须在 tailwind.config.js
文件中添加所需的特定颜色,可从 TailwindCSS palette 获得,如下所示:
tailwind.config.js
const defaultTheme = require('tailwindcss/defaultTheme');
const colors = require('tailwindcss/colors');
module.exports = {
mode: 'jit',
purge: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./vendor/laravel/jetstream/**/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php'
],
theme: {
colors: {
transparent: 'transparent',
current: 'currentColor',
//amber: colors.amber,
black: colors.black,
blue: colors.blue,
cyan: colors.cyan,
emerald: colors.emerald,
fuchsia: colors.fuchsia,
gray: colors.trueGray,
blueGray: colors.blueGray,
coolGray: colors.coolGray,
//trueGray: colors.trueGray,
warmGray: colors.warmGray,
green: colors.green,
indigo: colors.indigo,
lime: colors.lime,
orange: colors.orange,
pink: colors.pink,
purple: colors.purple,
red: colors.red,
rose: colors.rose,
sky: colors.sky,//warn - As of Tailwind CSS v2.2, `lightBlue` has been renamed to `sky`.
teal: colors.teal,
violet: colors.violet,
yellow: colors.amber,
white: colors.white,
},
extend: {
fontFamily: {
sans: ['Nunito', ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [require('@tailwindcss/forms'), require('@tailwindcss/typography')],
};
提示
您实际上可以在 node_modules/tailwindcss/colors.js
文件中检查可用的默认颜色。
选择颜色并保存文件后,现在再次运行
npm run dev
现在刷新网络浏览器的缓存并重新加载页面(您可能需要重新登录到 Laravel 应用程序)
我有一个 Laravel Jetstream 安装并使用 Tailwind CSS 但是在使用 Tailwind 组件时默认颜色不起作用。
我只想使用默认颜色,还不想自定义。
tailwind.config.js
const defaultTheme = require('tailwindcss/defaultTheme');
module.exports = {
mode: 'jit',
purge: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./vendor/laravel/jetstream/**/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
theme: {
extend: {
fontFamily: {
sans: ['Nunito', ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [require('@tailwindcss/forms'), require('@tailwindcss/typography')],
};
Jetstream 随 Tailwind 2.2.2 一起安装,该版本会出现此问题。我已尝试降级到 2.0.2,这是已知对我有用的最新版本,但也出现了问题
当使用相同的 HTML 代码时,在使用 tailwind 2.0.2 安装的 Laravel Breeze 中使用时可以正常工作。
例子html
<div class="flex-shrink-0 flex items-center justify-center w-16 bg-pink-600 text-white text-sm font-medium rounded-l-md">
</div>
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"@tailwindcss/forms": "^0.3.1",
"@tailwindcss/typography": "^0.4.0",
"alpinejs": "^3.0.6",
"axios": "^0.21",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"postcss-import": "^14.0.1",
"tailwindcss": "^2.2.2"
},
"dependencies": {
"daisyui": "^1.13.2"
}
}
在上面的示例中,bg-pink-600 未呈现。
您必须在 tailwind.config.js
文件中添加所需的特定颜色,可从 TailwindCSS palette 获得,如下所示:
tailwind.config.js
const defaultTheme = require('tailwindcss/defaultTheme');
const colors = require('tailwindcss/colors');
module.exports = {
mode: 'jit',
purge: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./vendor/laravel/jetstream/**/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php'
],
theme: {
colors: {
transparent: 'transparent',
current: 'currentColor',
//amber: colors.amber,
black: colors.black,
blue: colors.blue,
cyan: colors.cyan,
emerald: colors.emerald,
fuchsia: colors.fuchsia,
gray: colors.trueGray,
blueGray: colors.blueGray,
coolGray: colors.coolGray,
//trueGray: colors.trueGray,
warmGray: colors.warmGray,
green: colors.green,
indigo: colors.indigo,
lime: colors.lime,
orange: colors.orange,
pink: colors.pink,
purple: colors.purple,
red: colors.red,
rose: colors.rose,
sky: colors.sky,//warn - As of Tailwind CSS v2.2, `lightBlue` has been renamed to `sky`.
teal: colors.teal,
violet: colors.violet,
yellow: colors.amber,
white: colors.white,
},
extend: {
fontFamily: {
sans: ['Nunito', ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [require('@tailwindcss/forms'), require('@tailwindcss/typography')],
};
提示
您实际上可以在 node_modules/tailwindcss/colors.js
文件中检查可用的默认颜色。
选择颜色并保存文件后,现在再次运行
npm run dev
现在刷新网络浏览器的缓存并重新加载页面(您可能需要重新登录到 Laravel 应用程序)