简体   繁体   English

如何使用tailwindcss将样式文件夹移动到nextjs typescript中的src文件夹?

[英]How to move styles folder to src folder in nextjs typescript with tailwindcss?

i'm using nextjs with typescript and tailwindcss.我正在使用带有 typescript 和 tailwindcss 的 nextjs。 I want to move styles folder to src folder, i already added baseUrl with value src options in my tsconfig.json file, but I got an error like this :我想将styles文件夹移动到src文件夹,我已经在我的baseUrl文件中添加了带有值src选项的tsconfig.json ,但是出现了这样的错误:

    ./node_modules/next/dist/compiled/css-loader/cjs.js??ruleSet[1].rules[2].oneOf[5].use[1]!./node_modules/next/dist/compiled/postcss-loader/cjs.js??ruleSet[1].rules[2].oneOf[5].use[2]!./node_modules/tailwindcss/tailwind.css
TypeError: Object.fromEntries is not a function

and how i move styles folder to src folder, i want to make my folder structure simpler.以及如何将样式文件夹移动到 src 文件夹,我想让我的文件夹结构更简单。 thank you谢谢

config files must be stored in main root like next.config.js .配置文件必须存储在主根目录中,如 next.config.js 。 but style files can be stored in src directory.但是样式文件可以存储在 src 目录中。 read this doc: https://tailwindcss.com/docs/guides/nextjs阅读此文档: https : //tailwindcss.com/docs/guides/nextjs

I had the same problem after moving my files under src to clean up my root directory.将我的文件移动到src下以清理我的根目录后,我遇到了同样的问题。 I copied the config options for tailwind.config.js from this example repo from Tailwind Labs and found that it worked for me.我从 Tailwind Labs 的这个示例存储库中复制了tailwind.config.js的配置选项,发现它对我有用。

module.exports = {
  purge: {
    content: ['./src/**/*.{js,jsx,ts,tsx}', './next.config.js'],
  },
  ...

Delete the .next folder, then run the dev server again (with npm run dev ).删除.next文件夹,然后再次运行开发服务器(使用npm run dev )。

This worked in my case.这在我的情况下有效。 I'm guessing it's some kind of caching issue.我猜这是某种缓存问题。 Obviously you'll need to change your tailwind.config.js where the content should check ./src/**/*.{js,jsx,ts,tsx} rather than ./pages/**/*.{js,jsx,ts,tsx} .显然,您需要更改tailwind.config.js内容应检查的./src/**/*.{js,jsx,ts,tsx}而不是./pages/**/*.{js,jsx,ts,tsx}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 你如何阻止 typescript 复制 src 文件夹 - how do you stop the typescript from copying the src folder 当打字稿文件位于“ ./src”中时,如何构建输出文件夹 - How to build to output folder when the typescript files are located in './src' 使用 Typescript 3 构建到 dist/ 文件夹时保持 src/ 文件夹结构 - Maintain src/ folder structure when building to dist/ folder with Typescript 3 如何在使用 TypeScript 时使用 src 文件夹中的本地包设置 create-react-app? - How to set up create-react-app with local packages in src folder while using TypeScript? 打字稿/节点:构建应用程序时不会生成Src文件夹 - Typescript/Node: Src folder is not generated while building app 构建的 TypeScript 应用程序从错误的 src 而不是 dist 文件夹导入 - Built TypeScript application imports from wrong, src instead of dist, folder 如何默认导出TypeScript中的文件夹? - How to default export a folder in TypeScript? 从打字稿中的公共文件夹 Nextjs 导入给出错误:找不到模块 - Imports from public folder Nextjs in typescript give error: Cannot find module 如何使用 tsconfig 将.env 文件移动到构建文件夹中 - How to move .env file into build folder with tsconfig 如何将图像文件移动到文件夹? - How can I move image files to a folder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM