gpt4 book ai didi

reactjs - 故事书-顺风。我应该如何将顺风添加到故事书中

转载 作者:行者123 更新时间:2023-12-04 11:03:14 24 4
gpt4 key购买 nike

我想在故事书中添加顺风。这样 Stories 就会像在 Web 上一样呈现。
我用过 create-react-app project-name --template typescript创建项目。
然后安装顺风我跟着这个https://tailwindcss.com/docs/guides/create-react-app来自 tailwind 文档的说明。
完成后,我运行了代码 npm sb init .这确保了故事书的运行。
现在我需要告诉 storybook 使用 tailwindcss 进行样式设置。但我不知道如何。
我看到的每个其他答案都告诉编辑 postcss.config.js文件。
但我跟着这个https://tailwindcss.com/docs/guides/create-react-app我什至不必创建 postcss.config.js 文件的文档。所以我很困惑现在该怎么办。
为了清楚起见,我将在下面包含一些配置文件。craco.config.js

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

.storybook/preview.js
import "../src/index.css"

export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
}
.storybook/main.js
module.exports = {
"stories": [
"../src/**/*.stories.mdx",
"../src/**/*.stories.@(js|jsx|ts|tsx)"
],
"addons": [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/preset-create-react-app"
]
}
src/index.css
@tailwind base;
@tailwind components;
@tailwind utilities;
tailwind.config.js
module.exports = {
purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],

darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
package.json
`{
"name": "memory",
"version": "0.1.0",
"private": true,
"dependencies": {
"@craco/craco": "^6.0.0",
"@tailwindcss/postcss7-compat": "^2.0.2",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^12.0.0",
"@types/react": "^16.14.2",
"@types/react-dom": "^16.9.8",
"autoprefixer": "^9.8.6",
"postcss": "^7.0.35",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1",
"tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.0.2",
"typescript": "^4.0.3",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@storybook/addon-actions": "^6.1.11",
"@storybook/addon-essentials": "^6.1.11",
"@storybook/addon-links": "^6.1.11",
"@storybook/node-logger": "^6.1.11",
"@storybook/preset-create-react-app": "^3.1.5",
"@storybook/react": "^6.1.11"
}
}

tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}

最佳答案

故事书recommends使用 @storybook/addon-postcss 从现在开始自定义 postCSS 配置(而不是依赖自定义 postcss-loader ):

  • 将 postCSS 插件添加到您的安装中
    npm i -D @storybook/addon-postcss     # or
    yarn add -D @storybook/addon-postcss
  • 创建 postcss.config.js 在项目根
    // postcss.config.js
    module.exports = {
    plugins: {
    tailwindcss: {},
    autoprefixer: {},
    }
    }
  • 将插件添加到您的 .storybook/main.js
    // .storybook/main.js
    module.exports = {
    ...
    addons: [
    ...
    {
    name: '@storybook/addon-postcss',
    options: {
    cssLoaderOptions: {
    // When you have splitted your css over multiple files
    // and use @import('./other-styles.css')
    importLoaders: 1,
    },
    postcssLoaderOptions: {
    // When using postCSS 8
    implementation: require('postcss'),
    },
    },
    },
    ],
    };
  • .storybook/preview.js 中导入您的 css 文件
    // .storybook/preview.js
    import '../src/styles.css';
  • 关于reactjs - 故事书-顺风。我应该如何将顺风添加到故事书中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65495912/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com