Skip to content

Commit

Permalink
Fix GoogleChromeLabs#1394 for Windows support
Browse files Browse the repository at this point in the history
* Resolves the "initial" CSS modules differently so that Windows users don't get a posix path
* Uses`initialCssModule` from initial-css-plugin to identify these modules
  • Loading branch information
aryanpingle committed Feb 3, 2024
1 parent e217740 commit 430e732
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/css-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
normalize as nomalizePath,
sep as pathSep,
posix,
join as nodeJoin,
} from 'path';

import postcss from 'postcss';
Expand All @@ -30,6 +31,7 @@ import postCSSSimpleVars from 'postcss-simple-vars';
import cssNano from 'cssnano';
import camelCase from 'lodash.camelcase';
import glob from 'glob';
import { initialCssModule } from './initial-css-plugin';

const globP = promisify(glob);

Expand Down Expand Up @@ -152,7 +154,16 @@ export default function () {

if (!prefix) return;

const resolved = await this.resolve(id.slice(prefix.length), importer);
let resolved = null;
if (importer === initialCssModule) {
// Resolve the initial CSS differently
const cssPath = id.slice(prefix.length); // "shared/prerendered-app/path/to/file.css"
const absolutePath = nodeJoin(process.cwd(), 'src', cssPath); // absolute path
resolved = await this.resolve(absolutePath);
} else {
// Resolve normally
resolved = await this.resolve(id.slice(prefix.length), importer);
}
if (!resolved) throw Error(`Couldn't resolve ${id} from ${importer}`);

return prefix + resolved.id;
Expand Down
2 changes: 1 addition & 1 deletion lib/initial-css-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import glob from 'glob';
const globP = promisify(glob);

const moduleId = 'initial-css:';
const initialCssModule = '\0initialCss';
export const initialCssModule = '\0initialCss';

export default function initialCssPlugin() {
return {
Expand Down

0 comments on commit 430e732

Please sign in to comment.