【问题标题】:Tailwind Colors not compiling when used with Laravel Jetstream与 Laravel Jetstream 一起使用时,未编译 Tailwind 颜色
【发布时间】:2021-10-29 12:41:42
【问题描述】:

我安装了 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,这是已知对我有用但也出现问题的最新版本

当在 Laravel Breeze 中使用 tailwind 2.0.2 安装时,使用相同的 HTML 代码确实可以正常工作。

示例 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 没有渲染。

【问题讨论】:

  • 您是为生产编译还是在开发中编译?
  • npm run dev,我刚刚尝试了全新的 jetstream 安装,以确保我没有以某种方式错误配置它,但在全新安装时也会发生同样的事情
  • 它现在工作正常,我不太确定我做了什么来解决这个问题
  • 好的。您是否曾经运行过 npm build 或 prod ?默认情况下,tailwindCss 仅在生产环境中清除。也许是缓存问题。他在缓存中有产品css。如果再次发生,请清除浏览器缓存或打开另一个浏览器。

标签: laravel tailwind-css jetstream


【解决方案1】:

您必须在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 应用程序)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-11
    • 2022-10-15
    • 2021-09-27
    • 2021-06-16
    • 2022-12-21
    • 2022-12-11
    • 2021-09-02
    • 1970-01-01
    相关资源
    最近更新 更多