reactjs 情感css prop 样式不适用当使用vite

6ss1mwsb  于 2023-03-08  发布在  React
关注(0)|答案(1)|浏览(126)

维生素@3.1.6
@vitejs/插件React@2.1.6
@情绪/React@11.10.4React@17.0.2
我的vite配置

{
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 prop风格似乎不再是这应用到任何组件任何更多.因为我有多个版本的情感(10在依赖,和11在这项目本身)我别名一切到我的根依赖

7cwmlq89

7cwmlq891#

按照此article,似乎您的配置应该更改为

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

到这个

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

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

相关问题