indooorsman / esbuild-css-modules-plugin

A esbuild plugin to bundle css modules into js(x)/ts(x)
MIT License
92 stars 16 forks source link

Path issues on Windows #12

Closed mcosand-caltopo closed 2 years ago

mcosand-caltopo commented 2 years ago

Our team is using esbuild in with mixed Mac/Windows/Linux environments. Our config is

  plugins: [
    cssModulesPlugin({
      generateScopedName: "[local]-[hash:base64:5]",
      v2: true
    })
  ],

When I try to run the build on Windows, the build fails with errors similar to:

> src/components/MobileBarAboveMap.module.css:1:7 | error: Could not resolve "C:codeprojectcommon\buildwebpackstatic.esbuild_plugin_css_modules\"d416cc8e29af981e2f3f553ed3e7fdc08246953871b97af8d02b6f3a1ee38fsrccomponentsMobileBarAboveMap.modules_built.css" (mark it as external to exclude it from the bundle)
    1 | import "C:\code\project\common\build\webpack\static\.esbuild_plugin_css_modules\42d416cc8e29af981e2f3f553ed3e7fdc08246953871b97af8d02b6f3a1ee38f\src\components\MobileBarAboveMap.modules_built.css";

If I apply the following patch to the plugin I can get it to work, but would appreciate feedback:

@@ -121,12 +120,12 @@ const CssModulesPlugin = (options = {}) => {
             outdir,
             '.esbuild_plugin_css_modules',
             hex.slice(hex.length - 255, hex.length)
-          );
+          ).split(path.sep).join(path.posix.sep);

           const tmpCssFile = path.join(
             tmpDir,
             fullPath.replace(rootDir, '').replace(/\.modules?\.css$/, '.modules_built.css')
-          );
+          ).split(path.sep).join(path.posix.sep);
           fse.ensureDirSync(path.dirname(tmpCssFile));

           const { jsContent, cssContent } = await buildCssModulesJS(fullPath, {
indooorsman commented 2 years ago

will fix in next release, thanks, and sorry for late reply. https://github.com/indooorsman/esbuild-css-modules-plugin/blob/132caff7441e4fc7886507982bfd6e3a15afaba5/index.js#L143