css icon indicating copy to clipboard operation
css copied to clipboard

Allow explicitly specifying entryId when multiple entries exist

Open adonig opened this issue 9 months ago • 2 comments

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.

adonig avatar Jun 26 '25 10:06 adonig

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

A member of the Team first needs to authorize it.

vercel[bot] avatar Jun 26 '25 10:06 vercel[bot]

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.

1aron avatar Jun 26 '25 11:06 1aron