-
Notifications
You must be signed in to change notification settings - Fork 414
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
Rollup & PostCSS generates wrong style files with esm output + preserveModules #818
Comments
It looks like the I'm not familiar enough with Rollup to understand exactly why that prefix might be needed, and I see that it's been there |
@FancyVase you can fix the file extension by import linaria from '@linaria/rollup';
import postcss from 'rollup-plugin-postcss';
import babel from '@rollup/plugin-babel';
export default {
input: 'src/index.js',
output: [
// Works w/ PostCSS, not with Linaria
{
dir: 'dist/preserveModules',
format: 'esm',
preserveModules: true,
sourcemap: true,
sanitizeFileName: (name) => {
const match = /^[a-z]:/i.exec(name);
const driveLetter = match ? match[0] : '';
const fileName = driveLetter + name.substr(driveLetter.length).replace(/[\0?*:]/g, '_');
if (name.startsWith('@linaria:')) {
return fileName + '.js';
}
return fileName;
},
},
// Works w/ PostCSS & Linaria, but doesn't support tree-shaking
{
dir: 'dist/noPreserveModules',
format: 'esm',
sourcemap: true,
},
// Works w/ PostCSS & Linaria, but doesn't support tree-shaking
{
file: 'dist/cjs.bundle.js',
format: 'cjs',
sourcemap: true,
},
],
external: ['react'],
plugins: [
linaria({
sourceMap: process.env.NODE_ENV !== 'production',
}),
postcss({
exclude: 'node_modules/**',
}),
babel(),
],
}; |
@wmzy Thanks for the workaround! I can confirm that addresses the issue in @FancyVase's demo. 👌 I do still wonder if there might be a better way to address Vite compatibility than using the
|
|
Environment
^3.0.0-beta.4
^2.5.6
13.8.0
macOS Mojave 10.14.6
Description
I'm using Rollup with
@linaria/rollup
+rollup-plugin-postcss
to bundle React components that inject their styles on hydration.I also have an output format of
esm
w/preserveModules: true
in order to support tree-shaking.With this configuration, style files get generated incorrectly. Specifically, the built component JS file looks like this:
I would expect a
.js
import on the third line instead ofimport '../_virtual/LinariaComponent.jsx_52jihk.css';
Opening that file gives me:
Which is valid JS, but not valid CSS, and so attempting to use this component errors out.
This issue only appears when I set the Rollup
output.format
to'esm'
and setpreserveModules: true
, which I have to support tree-shaking.Reproducible Demo
Repo: https://github.com/FancyVase/test-linaria-rollup-postcss
I have a second
PostcssComponent.jsx
file that gets bundled as expected when importing a.pcss
file.I also included an
esm
output withoutpreserveModules
as well as acjs
output, both of which work as expected.The text was updated successfully, but these errors were encountered: