惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
SegmentFault 最新的问题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Attack and Defense Labs
Attack and Defense Labs
F
Full Disclosure
Vercel News
Vercel News
N
News | PayPal Newsroom
The GitHub Blog
The GitHub Blog
H
Hacker News: Front Page
H
Heimdal Security Blog
P
Privacy International News Feed
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cisco Blogs
L
Lohrmann on Cybersecurity
D
Docker
Recent Announcements
Recent Announcements
Security Archives - TechRepublic
Security Archives - TechRepublic
人人都是产品经理
人人都是产品经理
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Check Point Blog
博客园 - 叶小钗
Google Online Security Blog
Google Online Security Blog
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
S
Secure Thoughts
博客园 - Franky
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
P
Palo Alto Networks Blog
Latest news
Latest news
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
Last Week in AI
Last Week in AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
Hacker News: Ask HN
Hacker News: Ask HN
T
Threatpost
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学

不明のNetWorkOS

Libmodsecurity 的安装与使用 使用 GitHub 部署密钥部署代码 Supervisor 的安装与使用 PHP 中的 JIT 配置 IOC 服务容器 在 Nginx 中为 PHP 添加环境变量 Python 使用 virtualenv 部署 flask 项目 Git 基础命令 [转载] 免费 VPS 大全
在 Laravel 中的 Vue 组件无法使用 @apply 的解决方案
不明 · 2021-05-30 · via 不明のNetWorkOS

前写时间在写项目的时候使用到了 tailwindcss,该框架使用 PostCSS 作为预处理器,然而在使用 tailwindcss 的 @apply 方法时编译器出现了错误。

我的配置如下:

  • laravel 8.4
  • vue 3.0.11
  • postcss 8.3
  • tailwindcss 2.0.2

解决方案

这似乎是因为没有 postcss.config.js 文件造成的(在 tailwindcss 的官方安装方法里并没有这个在 Laravel 中安装 TailwindCSS),最终在 laravel-mix 的 GitHub 上找到了解决方案。
创建一个 postcss.config.js 文件在项目根目录中

const purgecss = require('@fullhuman/postcss-purgecss')({
  content: [
    './resources/**/*.blade.php',
    './resources/**/*.js',
    './resources/**/*.vue',
  ],
  whitelistPatterns: [ /-(leave|enter|appear)(|-(to|from|active))$/, /data-v-.*/, /v-deep/ ],
  whitelistPatternsChildren: [ /pretty$/, /xmx-.*$/, /^(.*?)\.tooltip/ ],
  defaultExtractor: content => content.match(/[\w-/.:]+(?<!:)/g) || []
})

module.exports = {
  plugins: [
      require('tailwindcss'),
      require('autoprefixer'),
      //...process.env.NODE_ENV === 'production' ? [purgecss] : []
  ]
}

请注释掉最后的生产优化,启用的话会导致预设的生产优化不起作用

然后将以下代码加入到你的 mix 配置中

.webpackConfig({
  module: {
    rules: [
      {
        test: /\.(postcss)$/,
        use: [
          'vue-style-loader',
          { loader: 'css-loader', options: { importLoaders: 1 } },
          'postcss-loader'
        ]
      }
    ],
  },
})

这样就可以成功编译了