我正在尝试为包含tailwindcss v1和postcss-import的react-static网站设置启动程序。我无法获取构建或启动过程来解析@import“ tailwindcss / xxx”指令。使用tailwindcss v0.7.4可以得到相同的结果
这就是我所做的...
react-static create
选择basic
选项yarn add tailwindcss@next
yarn add postcss-import
yarn tailwind init
postcss.config.js
src/app.css
语句替换了@import
的内容我尝试了许多选择,例如从其他现有项目开始,更改@import
参数。例如"../tailwindcss
,"src/tailwindcss
,"../src/tailwindcss
等
基本上我没有做任何更改错误的事情,只是无法解决的文件名。
但是,还有两个可能相关的观察结果。首先,安装了顺风,npx tailwind build src/styles.css -o src/app.css
从styles.css
生成了一个顺风文件。
第二,postcss导入根本没有发生-更改它对结果没有影响。
// tailwind.config.js
module.exports = {
theme: {},
variants: {},
plugins: []
}
// postcss.config.js
module.exports = {
plugins: [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
]
}
/* src/app.css */
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
错误消息是
Error: ✖ 「wdm」:
ERROR in /Users/tech/Projects/ReactStatic/my-static-site/src/app.css
Module build failed (from /Users/tech/Projects/ReactStatic/my-static-site/node_modules/extract-css-chunks-webpack-plugin/d ist/loader.js):
ModuleNotFoundError: Module not found: Error: Can't resolve './tailwindcss/base' in '/Users/tech/Projects/ReactStatic/my-s tatic-site/src'
at factory.create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/webpack/lib/Compilation.js:823:10)
at factory (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/webpack/lib/NormalModuleFactory.js:397:22)
at resolver (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/webpack/lib/NormalModuleFactory.js:130:21)
at asyncLib.parallel (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/webpack/lib/NormalModuleFactory.js: 224:22)
at /Users/tech/Projects/ReactStatic/my-static-site/node_modules/neo-async/async.js:2825:7
at /Users/tech/Projects/ReactStatic/my-static-site/node_modules/neo-async/async.js:6886:13
at normalResolver.resolve (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/webpack/lib/NormalModuleFactor y.js:214:25)
at doResolve (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:184:12)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn0 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js:3 3:10), <anonymous>:15:1)
at resolver.doResolve (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/UnsafeCachePl ugin.js:37:5)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn0 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js:3 3:10), <anonymous>:15:1)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn0 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js:3 3:10), <anonymous>:27:1)
at resolver.doResolve (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/DescriptionFi lePlugin.js:42:38)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn43 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js: 33:10), <anonymous>:16:1)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn0 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js:3 3:10), <anonymous>:27:1)
at resolver.doResolve (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/DescriptionFi lePlugin.js:42:38)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn1 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js:3 3:10), <anonymous>:16:1)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn0 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js:3 3:10), <anonymous>:15:1)
at fs.stat (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/DirectoryExistsPlugin.js :22:13)
at process.nextTick (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/CachedInputFile System.js:73:15)
at processTicksAndRejections (internal/process/task_queues.js:79:9)
@ /Users/tech/Projects/ReactStatic/my-static-site/src/App.js 7:0-19
@ /Users/tech/Projects/ReactStatic/my-static-site/src/index.js
@ multi react-hot-loader/patch ../lib/bootstrapPlugins.js ../lib/bootstrapTemplates.js index.js
Error: ✖ 「wdm」:
ERROR in /Users/tech/Projects/ReactStatic/my-static-site/src/app.css
Module build failed (from /Users/tech/Projects/ReactStatic/my-static-site/node_modules/extract-css-chunks-webpack-plugin/d ist/loader.js):
ModuleNotFoundError: Module not found: Error: Can't resolve './tailwindcss/base' in '/Users/tech/Projects/ReactStatic/my-s tatic-site/src'
at factory.create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/webpack/lib/Compilation.js:823:10)
at factory (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/webpack/lib/NormalModuleFactory.js:397:22)
at resolver (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/webpack/lib/NormalModuleFactory.js:130:21)
at asyncLib.parallel (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/webpack/lib/NormalModuleFactory.js: 224:22)
at /Users/tech/Projects/ReactStatic/my-static-site/node_modules/neo-async/async.js:2825:7
at /Users/tech/Projects/ReactStatic/my-static-site/node_modules/neo-async/async.js:6886:13
at normalResolver.resolve (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/webpack/lib/NormalModuleFactor y.js:214:25)
at doResolve (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:184:12)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn0 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js:3 3:10), <anonymous>:15:1)
at resolver.doResolve (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/UnsafeCachePl ugin.js:37:5)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn0 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js:3 3:10), <anonymous>:15:1)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn0 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js:3 3:10), <anonymous>:27:1)
at resolver.doResolve (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/DescriptionFi lePlugin.js:42:38)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn43 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js: 33:10), <anonymous>:16:1)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn0 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js:3 3:10), <anonymous>:27:1)
at resolver.doResolve (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/DescriptionFi lePlugin.js:42:38)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn1 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js:3 3:10), <anonymous>:16:1)
at hook.callAsync (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/Resolver.js:238:5 )
at _fn0 (eval at create (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/tapable/lib/HookCodeFactory.js:3 3:10), <anonymous>:15:1)
at fs.stat (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/DirectoryExistsPlugin.js :22:13)
at process.nextTick (/Users/tech/Projects/ReactStatic/my-static-site/node_modules/enhanced-resolve/lib/CachedInputFile System.js:73:15)
at processTicksAndRejections (internal/process/task_queues.js:79:9)
@ /Users/tech/Projects/ReactStatic/my-static-site/src/App.js 7:0-19
@ /Users/tech/Projects/ReactStatic/my-static-site/src/index.js
@ multi react-hot-loader/patch ../lib/bootstrapPlugins.js ../lib/bootstrapTemplates.js index.js
我希望开发服务器在处理源代码之后就可以启动。
完整源可在https://gitlab.com/support96/my-static-site.git
答案 0 :(得分:0)
嘿,我今天在这个问题上苦苦挣扎,设法解决了这个问题,并建立了一个图书馆,希望能帮助人们。
https://github.com/dev-warner/react-static-plugin-tailwindcss
在现有的静态站点中运行:
$ yarn add react-static-plugin-tailwindcss -D
然后将插件添加到您的static.config.js:
export default {
plugins: ["react-static-plugin-tailwindcss"]
};
现在,您可以在.css文件中添加@tailwind指令
@tailwind base;
@tailwind components;
@tailwind utilities;
该插件的功能概述只是将tailwindcss添加到您的postcss插件中。
Object.assign(postcssLoader.options, {
plugins: [require("tailwindcss"), ...(plugins.length ? plugins : [])]
});