Skip to content

Commit

Permalink
Fix CSS Modules + baseUrl (#3515)
Browse files Browse the repository at this point in the history
  • Loading branch information
drwpow authored Jun 30, 2021
1 parent 28884b5 commit a476850
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion snowpack/src/build/build-import-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ async function generateCssModuleImportProxy({
hmr: boolean;
config: SnowpackConfig;
}) {
const reqUrl = url.replace(new RegExp(`^${config.buildOptions.baseUrl}`), '/'); // note: in build, buildOptions.baseUrl gets prepended. Remove that for looking up CSS Module code
return `
export let code = ${JSON.stringify(code)};
let json = ${cssModuleJSON(url)};
let json = ${cssModuleJSON(reqUrl)};
export default json;
${
hmr
Expand Down
14 changes: 14 additions & 0 deletions test/snowpack/cssModules/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,18 @@ describe('cssModules', () => {
expect(result['_dist_/App.module.css']).not.toContain(`.App {`);
expect(result['_dist_/App.module.css.json']).toBeDefined();
});

it('Works with buildOptions.baseUrl set', async () => {
const result = await testFixture({
...files(),
'snowpack.config.js': dedent`
module.exports = {
buildOptions: {
baseUrl: '/subdir/'
}
};
`,
});
expect(result['src/App.module.css.proxy.js']).toContain(`let json = {"App":"_App_`);
});
});

1 comment on commit a476850

@vercel
Copy link

@vercel vercel bot commented on a476850 Jun 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.