我们弹出了tail-react-app,并希望将TailwindCSS添加到我们的项目中。然而,它似乎没有编译或添加样式到我们的元素。当我运行build命令时,生成的css文件中没有任何tailwind样式。
我运行了npx tailwindcss -i ./src/index.css -o ./dist/tailwind.css --watch
,在一个新的dist文件夹中编译了一个css文件。
由于我们的其他依赖关系,我们使用Tailwind v2。
// postcss.config.js
module.exports = {
plugins: [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer')
]
}
// tailwind.config.js
module.exports = {
purge: {
enabled: true,
content: [
"./src/**/*.{js,jsx,ts,tsx}",
"./src/**/*.html"
]
},
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
// index.css
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
...
// index.tsx
import "./index.css";
import App from "./app/App";
...
webpack.js.js未从弹出更改
我认为这些是相关的依赖关系:
"postcss": "7.0.39",
"postcss-flexbugs-fixes": "4.2.1",
"postcss-import": "15.1.0",
"postcss-loader": "3.0.0",
"postcss-normalize": "8.0.1",
"postcss-preset-env": "6.7.0",
"postcss-safe-parser": "5.0.2",
"react": "17.0.2",
"webpack": "4.44.2",
"webpack-dev-server": "3.11.1",
"webpack-manifest-plugin": "2.2.0",
"tailwindcss": "2.2.19"
更新:添加一些控制台日志后,webpack.js.js中getStyleLoaders
的输出是:
// "postcss" loader applies autoprefixer to our CSS.
// "css" loader resolves paths in CSS and adds assets as dependencies.
// "style" loader turns CSS into JS modules that inject <style> tags.
// In production, we use MiniCSSExtractPlugin to extract that CSS
// to a file, but in development "style" loader enables hot editing
// of CSS.
// By default we support CSS Modules with the extension .module.css
{
test: /\.css$/,
exclude: /\.module\.css$/,
use: [
{
loader: '/path/to/node_modules/mini-css-extract-plugin/dist/loader.js',
options: {}
},
{
loader: '/path/to/node_modules/css-loader/dist/cjs.js',
options: { importLoaders: 1, sourceMap: true }
},
{
loader: '/path/to/node_modules/postcss-loader/src/index.js',
options: {
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009',
},
stage: 3,
}),
// Adds PostCSS Normalize as the reset css with default options,
// so that it honors browserslist config in package.json
// which in turn let's users customize the target behavior as per their needs.
postcssNormalize(),
],
sourceMap: true
}
}
],
// Don't consider CSS imports dead code even if the
// containing package claims to have no side effects.
// Remove this when webpack adds a warning or an error for this.
// See https://github.com/webpack/webpack/issues/6571
sideEffects: true,
},
1条答案
按热度按时间zpgglvta1#
我们终于修好了。我不记得是哪个迭代修复了这个特殊的问题,因为我们遇到了很多问题。因此,我将在这里发布webpack,顺风和故事书的重要部分。
webpack.config.js
tailwind.config.js
storybook/main.js
仅供参考-使用此配置,图标不会在Storybook故事中呈现。我建议移动到Vite和Storybook 7。
react-app-env.d.ts