Closed karlnorling closed 5 months ago
Suggested fix would be:
https://github.com/indooorsman/esbuild-css-modules-plugin/blob/main/index.js#L230-L232
contents: forceBuild ? buildResult?.js : `import './${basename(path).replace(/\.css$/i, '.built.css')}';\n${
buildResult?.js
}`,
Thanks for reporting. I'll do more testings for it and come back to u asap
Hi @karlnorling ,
This behavior is by design:
with bundle: false
& force: true
& inject: false
, the import statement of built css file is needed to ensure content of css file would be kept in following build workflow.
What is your problem caused by this import statement?
@indooorsman Yes, I figured it was as intended. It's an issue with SSR loading of files trying to require none js files. I've worked around it by wrapping the loading / import / require of non js files in dynamic import checking window object.
With code usage of CssModulesPlugin and esbuild:
Due to the logic in: https://github.com/indooorsman/esbuild-css-modules-plugin/blob/main/lib/css.helper.js#L167-L172 It will add
import "${pluginCssNamespace}:${fixImportPath(relativePath)}";
whenthis.build.initialOptions.bundle
istrue
.But also when
this.build.initialOptions.bundle
isfalse
it will add the import here: https://github.com/indooorsman/esbuild-css-modules-plugin/blob/main/index.js#L205-L240 Specifically: https://github.com/indooorsman/esbuild-css-modules-plugin/blob/main/index.js#L230-L232Request would be to add logic to https://github.com/indooorsman/esbuild-css-modules-plugin/blob/main/index.js#L230-L232 not add the import if
forceBuild
is true.