koluch / esbuild-plugin-css-modules Goto Github PK
View Code? Open in Web Editor NEWPlugin for esbuild to support CSS-modules
Plugin for esbuild to support CSS-modules
This plugin fails on Windows because of backslashes in paths.
This is my case:
esbuild.build({
entryPoints: [ './src/index.js' ],
bundle: true,
outfile: './dist/bundle.js',
plugins:
[ esbuild_sass()
, esbuild_css_modules(
{ localIdentName: "[local]--[hash:8:md5:hex]"
, extension: '.module.css'
}
)
],
minify: !isDev(),
minifyIdentifiers: !isDev(),
minifySyntax: !isDev(),
minifyWhitespace: !isDev(),
sourcemap: isDev() ? 'external' : false,
platform: 'browser'
})
Which currently produces this result:
Error: Build failed with 1 error:
../../../AppData/Local/Temp/tmp-5848-66jQXSM4BQce/nuts/src/index.module.css:2:15: error: Could not resolve "C:Users\rmancAppDataAppDataLocalTemp\tmp-5848-66jQXSM4BQce\nutssrcindex.css" (mark it as external to exclude it from the bundle)
at failureErrorWithLog (C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:1449:15)
at C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:1131:28
at runOnEndCallbacks (C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:921:63)
at buildResponseToResult (C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:1129:7)
at C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:1236:14
at handleIncomingPacket (C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:706:9)
at Socket.readFromStdout (C:\Users\rmanc\Documents\projs\nuts\node_modules\esbuild\lib\main.js:576:7)
at Socket.emit (events.js:376:20)
at addChunk (internal/streams/readable.js:309:12)
error Command failed with exit code 1.
I noticed the path C:Users\rmancAppDataAppDataLocalTemp\tmp-5848-66jQXSM4BQce\nutssrcindex.css
and looked at the source:
esbuild-plugin-css-modules/index.ts
Lines 128 to 132 in 1f97e22
The generated code looks like this:
import "C:\Users\rmanc\AppData\AppData\Local\Temp\tmp-5848-66jQXSM4BQce\nuts\src\index.css";
const result = {"test":"test--h0aba64c6"};
export default result;
which obviously doesn't work.
--
I've managed to make it work by wrapping tmpFilePath
with https://github.com/sindresorhus/slash.
I'm writing a PR addressing this issue.
I'm trying this out with the latest esbuild 0.12.5, via a hacked-together version of snowpack, so I could have broken something there, but I'm finding that the output is mapping the wrong thing, I get values like:
var result3 = { "_Input_12syk_1": "h420205b8d955473ee51fd9760bbe0f66", "_Input___error_12syk_51": "hcc1aea921f960ec121be40adeeaf789b" };
var Input_module_default = result3;
Where I thought the keys should be something like just Input
and the value should be _Input_12syk_1
.
I am sporadically getting these messages when I try to chain esbuild-plugin-sass
followed by esbuild-plugin-css-modules
.
The error is not happening consistently, so I assume it's some sort of race condition.
❯ ./build.js
✘ [ERROR] Could not resolve "/var/folders/tg/vwvky4sd66vgvjkl0njrkl000000gn/T/tmp-87375-BNfLN4lwtij1/scrapbook-browser/lib/style/login.css"
../../../../../../var/folders/tg/vwvky4sd66vgvjkl0njrkl000000gn/T/tmp-87375-BNfLN4lwtij1/scrapbook-browser/lib/style/login.module.css:2:15:
2 │ import "/var/folders/tg/vwvky4sd66vgvjkl0njrkl000000gn/T/tmp-87375-BNfLN4lwtij1/scrapbook-browser/lib/style/login.css";
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
✘ [ERROR] Could not resolve "/var/folders/tg/vwvky4sd66vgvjkl0njrkl000000gn/T/tmp-87375-bqafdvagfR2x/scrapbook-browser/lib/style/login.css"
../../../../../../var/folders/tg/vwvky4sd66vgvjkl0njrkl000000gn/T/tmp-87375-bqafdvagfR2x/scrapbook-browser/lib/style/login.module.css:2:15:
2 │ import "/var/folders/tg/vwvky4sd66vgvjkl0njrkl000000gn/T/tmp-87375-bqafdvagfR2x/scrapbook-browser/lib/style/login.css";
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Could this plugin handle .module.scss
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.