New: Add bundle option
Closes #155
Hi @jonnitto, thanks for the suggestion and contribution. This looks interesting. Can you please add one test to make sure this does what it is supposed to ?
Thanks
I try to add a test, but I failed:
I've created a file named import.css in the folder fixtures with following content:
.foo {
background: red;
}
but the test don't get the path correctly:
test('Should import CSS file', (t) => {
t.plan(1);
return postcss()
.use(postcssLightningcss({
bundle: true,
}))
.process('@import "./fixtures/import.css";', {
from: path.join(__dirname, 'input.css'),
})
.then((result) => t.is(result.css, '.foo{background:red}'));
});
I always get following error:
imports › Should import CSS file
Rejected promise returned by test. Reason:
SyntaxError {
data: 'ResolverError',
message: 'No such file or directory (os error 2)',
}
SyntaxError: No such file or directory (os error 2)
at OnceExit (/PATH_TO_FOLDER/postcss-lightningcss/src/index.js:39:19)
at LazyResult.runAsync (/PATH_TO_FOLDER/postcss-lightningcss/node_modules/postcss/lib/lazy-result.js:298:21)
at LazyResult.async (/PATH_TO_FOLDER/postcss-lightningcss/node_modules/postcss/lib/lazy-result.js:160:30)
at LazyResult.then (/PATH_TO_FOLDER/postcss-lightningcss/node_modules/postcss/lib/lazy-result.js:404:17)
at /PATH_TO_FOLDER/postcss-lightningcss/test/imports.js:53:6
at Test.callFn (file:///PATH_TO_FOLDER/postcss-lightningcss/node_modules/ava/lib/test.js:525:26)
at Test.run (file:///PATH_TO_FOLDER/postcss-lightningcss/node_modules/ava/lib/test.js:534:33)
at Runner.runSingle (file:///PATH_TO_FOLDER/postcss-lightningcss/node_modules/ava/lib/runner.js:281:33)
at Runner.runTest (file:///PATH_TO_FOLDER/postcss-lightningcss/node_modules/ava/lib/runner.js:363:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
─
I pushed the tests, even if the last two are still failing…
Awesome, no worries, that's good enough, I'll have a look tonight
Hmm, so I looked into this and have bad news.
the reason the test fails with No such file or directory (os error 2) is that it tries to find the source file that's passed to postcss.
Because the bundle function expects a file as input, the code option I use for the rest doesn't work.
I think this means that this feature isn't possible in the context of postcss
Hm, that's pity. Would it be ok for you to remove the failing tests and create a release anyway? This feature is crucial for me and it allows to remove even one more PostCSS plugin
I don't understand, a release would be of no use to you.
The issue is not with the tests, it simply won't work because it expects a file as input.
Strange. In my enviroment the setting works fine. If i set bundle to true, the CSS get's bundled
Sorry for the delay.
I think the reason why you don't see this error is that the input file you specify is the one that is read by lightningcss.
To try this hypothesis try the following
- create a css file with some css in it
- create a postcss config with a few rules before
postcss-lightningcss - use
bundle
The output of the bundled file should not have the modifications performed before passing to postcss-lightningcss as it simply read the file from disk instead of reading the serialized version passed to it by postcss-lightningcss
Closing this as postcss-lightningcss won't be compatible with the bundle options for the reasons listed above