首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用vite时未应用情感css道具样式

使用vite时未应用情感css道具样式
EN

Stack Overflow用户
提问于 2022-10-10 09:45:57
回答 1查看 224关注 0票数 1

vite@3.1.6

@vitejs/plugin-react@2.1.6

@情感/反应11.10.4反应17.0.2

我的vite配置

代码语言:javascript
复制
{
plugins: [
    react({
        exclude: /\.stories\.(t|j)sx?$/,
        babel: {
            plugins: ["@emotion/babel-plugin"]
        }
    }),
    tsconfigPaths(),
    svgrPlugin()
],
esbuild: {
    logOverride: { "this-is-undefined-in-esm": "silent" },
    jsxFactory: `jsx`,
    jsxImportSource: "@emotion/react",
},
build: {
    outDir: "build",
},
server: {
    port: 3000,
},
optimizeDeps: {
    esbuildOptions: {
        define: {
            // Node.js global to browser globalThis
            global: "globalThis",
        },
        plugins: [
            // Enable esbuild polyfill plugins
            NodeGlobalsPolyfillPlugin({
                buffer: true,
            }),
        ],
    },
},
resolve: {
    preserveSymlinks: true,
    dedupe: ["react", "react-dom", "@emotion/styled", "@emotion/core"],
    alias: [
        {
            // this is required for the scss modules
            find: /^~(.*)$/,
            replacement: '$1',
        },
        {
            find: "@emotion/core",
            replacement: getRootPackageDir("@emotion/react"),
        },
        {
            find: "emotion-theming",
            replacement: getRootPackageDir("@emotion/react"),
        },
        {
            find: "@emotion/styled",
            replacement: getRootPackageDir("@emotion/styled"),
        },
    ],
}

}

css支持样式似乎不再应用于任何组件。由于我有多个情感版本(在依赖项中有10个版本,在项目本身中有11个版本),所以我将所有的内容都混在我的根目录中。

EN

回答 1

Stack Overflow用户

发布于 2022-10-20 15:05:24

遵循这个文章,似乎您的配置应该从下面的

代码语言:javascript
复制
plugins: [
    react({
        exclude: /\.stories\.(t|j)sx?$/,
        babel: {
            plugins: ["@emotion/babel-plugin"]
        }
    }),
    tsconfigPaths(),
    svgrPlugin()
],

到这个

代码语言:javascript
复制
lugins: [
    react({
        exclude: /\.stories\.(t|j)sx?$/,
        jsxImportSource: "@emotion/react",
        babel: {
            plugins: ["@emotion/babel-plugin"]
        }
    }),
    tsconfigPaths(),
    svgrPlugin()
],

而不是作为esbuild配置的一部分

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74012964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档