我正在try 将TailwindCSS添加到我现有的Express JS+React应用程序中.我已经try 了许多不同的教程,比如这本https://tailwindcss.com/docs/installation针对常规JS的教程,以及这本专为Create React App https://tailwindcss.com/docs/guides/create-react-app制作的教程.后来,我在express js https://daily.dev/blog/how-to-use-tailwindcss-with-node-js-express-and-pug上try 了本教程

这是我的项目供参考https://github.com/twbluenaxela/LVChineseBusinessCrawler/pull/35

下面是我的json包脚本

"scripts": {
"predeploy": "npm install",
"dev": "react-scripts --openssl-legacy-provider start",
"clientbuild": "npm install && node server/index.js",
"test": "react-scripts test",
"build": "react-scripts --openssl-legacy-provider build",
"build:css": "postcss src/index.css -o dist/output.css",
"eject": "react-scripts eject",
"start_cors": "node cors.js",
"start": "node server/index.js" }

这是我的css配置js帖子

module.exports = {
  plugins: [require('tailwindcss'), require('autoprefixer')],
}

这是我的tailwind 配置

module.exports = {
    content: [
      "./src/**/*.{js,jsx,ts,tsx}",
      "./build/**/*.html"
    ],
    theme: {
      extend: {},
    },
    plugins: [
      {
        tailwindcss: {},
        autoprefixer: {},
      },
    ],
  };

这是我在索引html中指向我的dist文件夹的链接(位置:public/index.html)

    <link href="/dist/output.css" rel="stylesheet">

这是我的快车.我认为它可能需要处理express首先加载这些通过运行"react scripts build"脚本生成的"chunk"文件,然后默认为那样,而不是tailwind ?

// Have Node serve the files for our built React app
app.use(express.static(path.resolve(__dirname, '../build')));
//this is for tailwind.
app.use(express.static(path.join(__dirname, 'dist')));


// Stop browser from sending requests to get the icon
app.get('../build/favicon.ico', (req, res) => res.status(204).end());

// All other GET requests not handled before will return our React app
app.get('*', (req, res) => {
  res.sendFile(path.resolve(__dirname, '../build/index.html'));
});

// Start the server and listen on the preconfigured port
app.listen(port, () => console.log(`App started on port ${port}.`));

这是我重新加载页面时从服务器获取的日志(log)

gitpod /workspace/LVChineseBusinessCrawler (NodemonFix) $ npm run start

> pachong@0.1.0 start
> node server/index.js

App started on port 3001.
GET / 200 3.406 ms - 2371
GET /dist/output.css 200 1.897 ms - 2371
GET /static/css/main.a6b1053c.chunk.css 200 0.556 ms - 108
GET /static/js/2.b2955d3e.chunk.js 200 0.561 ms - 188544
GET /static/js/main.bfafc08b.chunk.js 200 0.453 ms - 2862
GET /static/css/main.a6b1053c.chunk.css.map 200 0.609 ms - 227
GET /favicon.ico 200 0.719 ms - 3870
GET /manifest.json 200 0.401 ms - 319

正如你所看到的,它似乎知道我的输出在哪里.css是,我假设它加载它?那么,也许是"区块css覆盖了它"?

    <h1 class="text-3xl font-bold underline">

它只显示普通的h1,没有任何下划线或任何东西.

编辑1:

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

推荐答案

试试这个link.

它有设置reacttailwind 的详细说明

请仔细遵循所有步骤.并确保其工作正常,然后添加express模块

希望有帮助!

Javascript相关问答推荐

TestCafe预计文本等于以下内容之一

无法在page. evalve()内部使用外部函数

Vue Quill css仅应用于我的第一个Quill Editor组件+如何自定义工具栏

在时间轴完整日历中显示日期标题

React对话框模式在用户单击预期按钮之前出现

如何通过在提交时工作的函数显示dom元素?

使用json文件字符串来enum显示类型字符串无法按照计算的enum成员值的要求分配给类型号

过滤对象数组并动态将属性放入新数组

从mat—country—select获取整个Country数组

在Angular中将样式应用于innerHTML

如何找出摆线表面上y与x相交的地方?

Google maps API通过API返回ZERO_RESULTS,以获得方向请求,但适用于Google maps

使用LocaleCompare()进行排序时,首先使用大写字母

try 使用javascript隐藏下拉 Select

如何将未排序的元素追加到数组的末尾?

如何在Svelte中从一个codec函数中调用error()?

JavaScript不重定向配置的PATH

如何在我的Next.js项目中.blob()我的图像文件?

无法检索与Puppeteer的蒸汽游戏的Bundle 包价格

如果对象中的字段等于某个值,则从数组列表中删除对象