Skip to content

Allow explicitly specifying entryId when multiple entries exist #404

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

Open
wants to merge 1 commit into
base: rc
Choose a base branch
from

Conversation

adonig
Copy link

@adonig adonig commented Jun 26, 2025

Problem

In Vite projects where both src/main.tsx (used for vite serve) and src/index.ts (used for vite build) exist, the MasterCSS Vite plugin currently always picks src/index.ts as the entry due to glob ordering (alphabetical by default).

Solution

This PR introduces a new entryId option for the masterCSS() plugin. It allows users to explicitly define the desired entry point:

masterCSS({
  entryId: process.env.NODE_ENV === 'production' 
    ? 'src/index.ts' 
    : 'src/main.tsx',
})

Usage

No breaking changes. If entryId is not provided, the plugin behavior remains unchanged.

Copy link

vercel bot commented Jun 26, 2025

@adonig is attempting to deploy a commit to the Aoyue Team on Vercel.

A member of the Team first needs to authorize it.

@1aron
Copy link
Member

1aron commented Jun 26, 2025

This is a good strategy. Here's an unpublished reference:

import type { Pattern } from 'fast-glob'
import { Options as ExtractorOptions } from '@master/css-extractor'

/* The default options */
const options: PluginOptions = {
    mode: 'runtime',
    config: 'master.css',
    injectNormalCSS: true,
    injectRuntime: true,
    injectVirtualModule: true,
    avoidFOUC: true,
}

export default options

export interface PluginOptions {
    /**
     * Defines how Master CSS should be integrated into the build.
     *
     * - `'runtime'`: Detects the application's entry file, automatically injects the initialization of CSSRuntime, and imports the config code.
     * - `'extract'`: Detects the application's entry file, automatically imports the `virtual:master.css` module, and triggers the static extraction workflow.
     * - `'pre-render'`: Renders all `*.html` dependencies and injects CSS internally. This mode may be integrated with other SSR capabilities.
     * - `'progressive'`: Combines `'runtime'` and `'pre-render'` modes.
     * - `null`: Disables automatic integration
     */
    mode?: 'runtime' | 'extract' | 'progressive' | 'pre-render' | null

    /**
     * Glob pattern(s) or extractor options for the static extraction mode
     *
     * - Provide a glob `Pattern` to manually specify your extractor config.
     * - Or provide `ExtractorOptions` for fine-grained extractor configuration.
     */
    extractor?: ExtractorOptions | Pattern

    /**
     * Path to the Master CSS config file.
     * Defaults to `'master.css'`.
     */
    config?: string

    /**
     * Whether to inject the `@master/normal.css` module into the entry file.
     */
    injectNormalCSS?: boolean

    /**
     * Whether to include Master CSS’s runtime engine into the entry file.
     */
    injectRuntime?: boolean

    /**
     * Whether to register the virtual module `virtual:master.css`.
     * Allows importing it directly in user code for dynamic injection.
     */
    injectVirtualModule?: boolean

    /**
     * Prevents Flash of Unstyled Content (FOUC) during the initial render.
     * Useful in Runtime
     */
    avoidFOUC?: boolean
}

Perhaps we just need to disable automatic injection and let developers import the modules manually as they normally would.

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

Successfully merging this pull request may close these issues.

2 participants