laravel - 将 Tailwind CSS v2.0+ 安装到 Laravel 8 中可以工作,但运行时什么也不做

标签 laravel webpack tailwind-css postcss

我正在尝试将 Tailwind CSS v2.0 安装到干净的 Laravel 安装中,但是当我运行 npm run prod (或 dev)时,编译后的 CSS 文件只是源代码的副本。

我正在采取的步骤:

> laravel new twtest
> cd twtest
> php artisan -V
# Laravel Framework 8.16.1
> npm install
> npm install tailwindcss postcss autoprefixer
> touch postcss.config.js
# Add the postCss default from https://tailwindcss.com/docs/installation
# Add the three @tailwind commands into /resources/css/app.css
> npm run dev

编译成功,但输出 CSS(在 public/css/app.css 中)列出了相同的三个 tailwind 命令,其中应包含所有已编译的 Tailwind CSS:

@tailwind base;
@tailwind components;
@tailwind utilities;

最佳答案

确保您拥有最新版本:

npm install -D laravel-mix@latest tailwindcss@latest postcss@latest autoprefixer@latest --save-dev

仔细检查您的 package.json 是否包含最新的脚本条目以支持最新版本的 Laravel Mix。

"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"
},

并且,删除 postcss.config.js 并在生成 postcss.config.js 的同时生成 tailwind.config.js。

npx tailwindcss init -p

将以下内容添加到/resources/css/app.css 中。

@tailwind base;
@tailwind components;
@tailwind utilities;

完整的步骤是:

laravel new twtest
cd twtest
npm install -D laravel-mix@latest tailwindcss@latest postcss@latest autoprefixer@latest --save-dev
npx tailwindcss init
# Add the three @tailwind entries into /resources/css/app.css
npm run prod

关于laravel - 将 Tailwind CSS v2.0+ 安装到 Laravel 8 中可以工作,但运行时什么也不做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65010873/

相关文章:

php - 在不使用付费服务作为 Pusher 的情况下创建 Laravel 广播的最简单方法是什么?

Laravel 翻译值 required_if

javascript - 使用 webpack-dev-server 观察本地依赖关系

vue.js - 如何使用Vue在Electron应用程序中访问本地镜像

javascript - 隐藏的 Tailwind 移动设备无法正常工作

tailwind-css - 有没有办法添加 translate-z-[ ] 实用程序类

php - Laravel:如何在没有数据库的情况下对用户进行身份验证

javascript - 如何制作一个具有 2 个窗口的 Electron react 应用程序 - 一个普通的窗口和一个用于托盘的窗口

html - 管理 gem — 将自定义 HTML 类传递到字段中

php - 如何从 Trait 获取父命名空间