Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The styleName of a element which have multiple child elements cannot be transform in production build #1

Closed
ruxes7 opened this issue Apr 2, 2022 · 1 comment

Comments

@ruxes7
Copy link

ruxes7 commented Apr 2, 2022

Its perfectly works in dev but some elements styleNames cannot be transform in production.
vite.config.js

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import reactInlineCSSModulePlugin from "react-inline-css-module/dist/vite-plugin";
import Inspect from 'vite-plugin-inspect'
const generateScopedName = "[path]___[name]___[local]___[hash:base64:5]";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    Inspect(),
    reactInlineCSSModulePlugin( { reactVariableName: 'React' } ),

  ],
  css: {
    modules: {
      generateScopedName,
    },
  },
})

App.tsx

import { useState, FC } from 'react'
import logo from './logo.svg'
import './style.module.scss'

const App: FC = () => {
  const [count, setCount] = useState(0)

  return (
    <div styleName="App">
      <header styleName="hoge"> 
        <img src={logo} styleName="foo" alt="logo" />
        <header styleName="App-header">
          <img src={logo} styleName="App-logo" alt="logo" />
          <p>Hello Vite + React!</p>
          <p>
            <button type="button" onClick={() => setCount((count) => count + 1)}>
              count is: {count}
            </button>
          </p>
          <p>
            Edit <code>App.tsx</code> and save to test HMR updates.
          </p>
          <p>
            <a
              styleName="App-link"
              href="https://reactjs.org"
              target="_blank"
              rel="noopener noreferrer"
            >
              Learn React
            </a>
            {' | '}
            <a
              styleName="App-link"
              href="https://vitejs.dev/guide/features.html"
              target="_blank"
              rel="noopener noreferrer"
            >
              Vite Docs
            </a>
          </p>
        </header>
      </header>
    </div>
  )
}

export default App

The dom in production build (vite build && vite preview)

<div class="src-___style-module___App___CnhW9">
    <header stylename="hoge">
        <img src="/assets/logo.ecc203fb.svg" alt="logo" class="src-___style-module___foo___aUHr3">
        <header stylename="App-header">
            <img src="/assets/logo.ecc203fb.svg" alt="logo" class="src-___style-module___App-logo___dCJLA">
            <p>Hello Vite + React!</p><p><button type="button">count is: 0</button></p>
            <p>Edit <code>App.tsx</code> and save to test HMR updates.</p>
            <p>
                <a href="https://reactjs.org" target="_blank" rel="noopener noreferrer" class="src-___style-module___App-link___6Yqd4">Learn React</a> | 
                <a href="https://vitejs.dev/guide/features.html" target="_blank" rel="noopener noreferrer" class="src-___style-module___App-link___6Yqd4">Vite Docs</a>
            </p>
        </header>
    </header>
</div>

See the problems at header's styleName
How to resolve this?

@anjianshi
Copy link
Owner

The class name eg. 'hoge' 'App-header' must appears in 'style.module.scss', otherwise it cannot be translate.
Or can you provide a complete demo?

@ruxes7 ruxes7 closed this as completed Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants