我创建了一个新的 vue3 + Vite,Storybook 项目。
"@storybook/vue3": "^8.6.12",
"@storybook/vue3-vite": "^8.6.12",
"vite": "^6.2.0",
并安装这些 npm 包:
"@storybook/addon-postcss": "^2.0.0",
"@tailwindcss/postcss": "^4.1.4",
"postcss": "^8.5.3",
"tailwindcss": "^4.1.4",
// and edit .storybook/main.ts
addons: [
+ {
+ name: "@storybook/addon-postcss",
+ options: {
+ postcssLoaderOptions: {
+ implementation: require("postcss"),
+ },
+ },
+ }
]
// and edit .storybook/preview.ts
+ import '../packages/style/tailwindcss.css'
/* content of the packages/style/tailwindcss.css */
@import "tailwindcss";
// add the postcss.config.js
module.exports = {
plugins: {
'@tailwindcss/postcss': {},
// autoprefixer: {}
// require('postcss-color-rebeccapurple'),
}
}
// edit package.json
- "type": "module"
Why delete this line?
Failed to load PostCSS config (searchPath: /Users/lifaqi/noliebe/tool-cabinet): [ReferenceError] module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/lifaqi/noliebe/tool-cabinet/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/lifaqi/noliebe/tool-cabinet/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///Users/lifaqi/noliebe/tool-cabinet/postcss.config.js?t=1745546527838:1:1
at ModuleJob.run (node:internal/modules/esm/module_job:271:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:578:26)
at async req$3 (file:///Users/lifaqi/noliebe/tool-cabinet/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/dep-glQox-ep.js:14751:13)
at async Object.search (file:///Users/lifaqi/noliebe/tool-cabinet/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/dep-glQox-ep.js:14493:23)
so i delete them, run stoybook, and is clear.
但是 tailwindcss 无法在我的组件上运行。我该怎么办?这是我第一次使用 Storybook。我使用[email protected]