我正在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;