如何将外部CSS导入后风的app.css

发布于 2025-01-24 04:32:14 字数 1071 浏览 2 评论 0 原文

我正在尝试使用第三方node_nodules,其中包含我尝试以各种方式导入tailwinds app.cs.cs.css.css的CSS。 Tailwind CSS的东西正在进口和工作正常。

关于我做错了什么的想法?

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

/* DID NOT WORK: */
/* @import '/node_modules/swiper/swiper-bundle.css';
   @import '/node_modules/swiper/swiper-bundle.min.css';
   @import '/node_modules/swiper/swiper.min.css'; */

/* DID NOT WORK: */
/* @import 'swiper/swiper-bundle.css';
   @import 'swiper/swiper-bundle.min.css';
   @import 'swiper/swiper.min.css'; */

/* DID NOT WORK: */
/* @import '~swiper/swiper-bundle.css';
   @import '~swiper/swiper-bundle.min.css';
   @import '~swiper/swiper.min.css'; */

我的post.config.js看起来像这样:

    module.exports = {
  plugins: {
    'postcss-import': {},
    tailwindcss: {},
    autoprefixer: {},
  },
}

当我尝试在remix中进行npm run构建时,它只是将输出作为导入语句的字符串:

I'm trying to use a 3rd party node_nodules which contains css i've tried importing it in various ways into tailwinds app.css in a remix application.
The tailwind CSS stuff is being imported and working fine.

Any ideas on what i'm doing wrong?

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

/* DID NOT WORK: */
/* @import '/node_modules/swiper/swiper-bundle.css';
   @import '/node_modules/swiper/swiper-bundle.min.css';
   @import '/node_modules/swiper/swiper.min.css'; */

/* DID NOT WORK: */
/* @import 'swiper/swiper-bundle.css';
   @import 'swiper/swiper-bundle.min.css';
   @import 'swiper/swiper.min.css'; */

/* DID NOT WORK: */
/* @import '~swiper/swiper-bundle.css';
   @import '~swiper/swiper-bundle.min.css';
   @import '~swiper/swiper.min.css'; */

My post.config.js looks like this:

    module.exports = {
  plugins: {
    'postcss-import': {},
    tailwindcss: {},
    autoprefixer: {},
  },
}

When I try to do npm run build in remix it just gets output as string of the import statement:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素衣风尘叹 2025-01-31 04:32:15

不确定是否已经回答,但是我发现使用PostCSS-Import与Tailwind(也使用Remix Vite Spa)解决了我的问题。在Postcss.config.js文件中,请确保您有以下内容:

export default {
    plugins: {
        'postcss-import': {},
        'tailwindcss/nesting': 'postcss-nesting',
        tailwindcss: {},
        autoprefixer: {},
    },
}

从那里开始,请确保您正确设置了您的导入,因为这确实使用了严格的CSS导入,如下所示: https://tailwindcss.com/docs/using-with-preprocessors#build time-imports

因此,我的tailwind.css(主要CSS文件)看起来像:

@import "./libraryStyles/tailwindbase.css";
/* 
  Will need to add tailwind components, utilities, etc in separate
  file if we need to use those appropriately
*/
@import "./libraryStyles/remixRootStyle.css"

图书馆风格的文件夹既有尾风基类,又保存着我从混音github中撕下的样式。 tailwindbase.css文件看起来像我的应用程序:

@tailwind base;

@layer base {
    :root {
      --background: 0 0% 100%;
      --foreground: 20 14.3% 4.1%;
  
      --card: 0 0% 100%;
      --card-foreground: 20 14.3% 4.1%;
   
      --popover: 0 0% 100%;
      --popover-foreground: 20 14.3% 4.1%;
   
      --primary: 24 9.8% 10%;
      --primary-foreground: 60 9.1% 97.8%;
   
      --secondary: 60 4.8% 95.9%;
      --secondary-foreground: 24 9.8% 10%;
   
      --muted: 60 4.8% 95.9%;
      --muted-foreground: 25 5.3% 44.7%;
   
      --accent: 60 4.8% 95.9%;
      --accent-foreground: 24 9.8% 10%;
   
      --destructive: 0 84.2% 60.2%;
      --destructive-foreground: 60 9.1% 97.8%;
  
      --border: 20 5.9% 90%;
      --input: 20 5.9% 90%;
      --ring: 20 14.3% 4.1%;
   
      --radius: 0.5rem;
    }
   
    .dark {
      --background: 20 14.3% 4.1%;
      --foreground: 60 9.1% 97.8%;
   
      --card: 20 14.3% 4.1%;
      --card-foreground: 60 9.1% 97.8%;
   
      --popover: 20 14.3% 4.1%;
      --popover-foreground: 60 9.1% 97.8%;
   
      --primary: 60 9.1% 97.8%;
      --primary-foreground: 24 9.8% 10%;
   
      --secondary: 12 6.5% 15.1%;
      --secondary-foreground: 60 9.1% 97.8%;
   
      --muted: 12 6.5% 15.1%;
      --muted-foreground: 24 5.4% 63.9%;
   
      --accent: 12 6.5% 15.1%;
      --accent-foreground: 60 9.1% 97.8%;
   
      --destructive: 0 62.8% 30.6%;
      --destructive-foreground: 60 9.1% 97.8%;
   
      --border: 12 6.5% 15.1%;
      --input: 12 6.5% 15.1%;
      --ring: 24 5.7% 82.9%;
    }
  }
   
  @layer base {
    * {
      @apply border-border;
    }
    body {
      @apply bg-background text-foreground;
    }
  }

Not sure if this has been answered yet or not, but I found that using postcss-import with tailwind (also using Remix Vite SPA) resolved my problems. In the postcss.config.js file, make sure you have the following:

export default {
    plugins: {
        'postcss-import': {},
        'tailwindcss/nesting': 'postcss-nesting',
        tailwindcss: {},
        autoprefixer: {},
    },
}

From there, make sure you setup your imports correctly as this does use strict CSS importing as detailed here: https://tailwindcss.com/docs/using-with-preprocessors#build-time-imports.

So, my tailwind.css (main css file) looks like this:

@import "./libraryStyles/tailwindbase.css";
/* 
  Will need to add tailwind components, utilities, etc in separate
  file if we need to use those appropriately
*/
@import "./libraryStyles/remixRootStyle.css"

Where the libraryStyles folder holds both the tailwind base classes and the style I ripped from the remix github. The tailwindbase.css file looks like this for my app:

@tailwind base;

@layer base {
    :root {
      --background: 0 0% 100%;
      --foreground: 20 14.3% 4.1%;
  
      --card: 0 0% 100%;
      --card-foreground: 20 14.3% 4.1%;
   
      --popover: 0 0% 100%;
      --popover-foreground: 20 14.3% 4.1%;
   
      --primary: 24 9.8% 10%;
      --primary-foreground: 60 9.1% 97.8%;
   
      --secondary: 60 4.8% 95.9%;
      --secondary-foreground: 24 9.8% 10%;
   
      --muted: 60 4.8% 95.9%;
      --muted-foreground: 25 5.3% 44.7%;
   
      --accent: 60 4.8% 95.9%;
      --accent-foreground: 24 9.8% 10%;
   
      --destructive: 0 84.2% 60.2%;
      --destructive-foreground: 60 9.1% 97.8%;
  
      --border: 20 5.9% 90%;
      --input: 20 5.9% 90%;
      --ring: 20 14.3% 4.1%;
   
      --radius: 0.5rem;
    }
   
    .dark {
      --background: 20 14.3% 4.1%;
      --foreground: 60 9.1% 97.8%;
   
      --card: 20 14.3% 4.1%;
      --card-foreground: 60 9.1% 97.8%;
   
      --popover: 20 14.3% 4.1%;
      --popover-foreground: 60 9.1% 97.8%;
   
      --primary: 60 9.1% 97.8%;
      --primary-foreground: 24 9.8% 10%;
   
      --secondary: 12 6.5% 15.1%;
      --secondary-foreground: 60 9.1% 97.8%;
   
      --muted: 12 6.5% 15.1%;
      --muted-foreground: 24 5.4% 63.9%;
   
      --accent: 12 6.5% 15.1%;
      --accent-foreground: 60 9.1% 97.8%;
   
      --destructive: 0 62.8% 30.6%;
      --destructive-foreground: 60 9.1% 97.8%;
   
      --border: 12 6.5% 15.1%;
      --input: 12 6.5% 15.1%;
      --ring: 24 5.7% 82.9%;
    }
  }
   
  @layer base {
    * {
      @apply border-border;
    }
    body {
      @apply bg-background text-foreground;
    }
  }

江城子 2025-01-31 04:32:15

只需在input.css中添加一行:

@import '/reset.css';

/* other code */

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

Just add one line in input.css:

@import '/reset.css';

/* other code */

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文