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

Fix style compilation for file paths containing webpack template strings #1247

Merged
merged 14 commits into from
Feb 1, 2024
Merged
7 changes: 7 additions & 0 deletions .changeset/eleven-oranges-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@vanilla-extract/webpack-plugin': patch
---

Fixes a bug that was causing style compilation to fail on paths containing [webpack template strings] such as `[id]`.

[webpack template strings]: https://webpack.js.org/configuration/output/#template-strings
11 changes: 9 additions & 2 deletions packages/webpack-plugin/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,16 @@ function compileVanillaSource(
loader._compiler.webpack && loader._compiler.webpack.version,
);
const compat = createCompat(isWebpack5);
// Child compiler will compile vanilla-extract files to be evaled during compilation
const outputOptions = { filename: loader.resourcePath };

// Escape webpack template strings in output files so they don't get replaced
// Non-standard escape syntax, see the docs https://webpack.js.org/configuration/output/#template-strings
const outputOptions = {
filename: loader.resourcePath
.replaceAll('[', '[\\')
askoufis marked this conversation as resolved.
Show resolved Hide resolved
.replaceAll(']', '\\]'),
askoufis marked this conversation as resolved.
Show resolved Hide resolved
askoufis marked this conversation as resolved.
Show resolved Hide resolved
};

// Child compiler will compile vanilla-extract files to be evaled during compilation
const compilerName = getCompilerName(loader.resourcePath);
const childCompiler = getRootCompilation(loader).createChildCompiler(
compilerName,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ESNEXT" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": ["es2019", "es2017", "dom"],
"lib": ["es2021", "dom"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Required for tsc to recognize replaceAll. It was added in node 15, so IMO it's safe to use.

"noEmit": true,
"noImplicitAny": true,
"noUnusedLocals": true,
Expand Down