-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
build production bug Modified the contents of the original document #155
Comments
Hi, @hppking. Could you please provide a bit more detail on this issue? I don't understand, what you mean. |
@Machy8 |
Cannot modify source file todo-list.jsx |
This behavior is actually correct. Since some frameworks (Symfony, Laravel, Next) don't have hooks for generating files as NuxtJS does. Because of that, Stylify must access the files before framework compilers, therefore it processes source files directly. However try to add bundles: [
{
outputFile: './src/stylify.css',
files: ['./src/**/*.jsx'],
rewriteSelectorsInFiles: false,
},
], I have tested it in SolidJS example and it seems to work (I have updated the example). Then, you can run |
Good |
But not works in Svelte component parent Dev: <div class="padding:10px background:pink">
<p class="color:blue font-style:italic">Cat</p>
</div> Build: <div class="padding:10px background:pink">
<p class="c d">Cat</p>
</div> |
Hi @mzaini30. Are you using SvelteKit or svelte+vite or any other combination? If it is a Stackblitz playground, could you share a link? Could you please send the parent and child component template? I will try to reproduce the error and fix it. |
I using it: https://github.com/mzaini30/svelte |
I have forked your example. Here is your example with a working configuration: https://stackblitz.com/edit/github-z2waev?file=vite.config.js. The problem is with Svelte compilation under the hood with the combination with Vite converts The only option here now is to remove the If you need to test the production build process locally without selectors mangling or disabling it entirely, you can set the const stylifyPlugin = stylifyVite({
// ...
bundles: [ /* */ ],
compiler: {
mangleSelectors: false
}
}); Please let me know if it works. P.S. If you use const stylifyPlugin = stylifyVite({
// ...
compiler: {
selectorsAreas: ['(?:^|\\s+)class:(\\S+)=["\']']
}
}); I will add that to the Stylify in the next version, so you this will not be needed anymore. |
I usually build it locally because I using compiled Svelte for Android app webview 😅 Okay, I'll use mangleSelectors false |
Hm, this is bad. Sorry for that. I have tried to configure some parsing before you send me your repo, but Svelte compiles that into a ton of variants of output, so I haven't send any patch. Will have to look into it. But I need to test it first. You can possibly check if there is for example If the Something like: import fs from 'fs';
const isLocalEnv = fs.existsSync('./.env.local');
const stylifyPlugin = stylifyVite({
// ...
bundles: [ /* */ ],
compiler: {
mangleSelectors: !isLocalEnv
}
}); But if you release the package after manual bundling, this will probably not be what you need. |
Nice idea. I'll create scripts like |
Try it. If you find any issues, let me know. |
Solved import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import legacy from "@vitejs/plugin-legacy";
import pages from "vite-plugin-pages-svelte";
import { stylifyVite } from '@stylify/unplugin';
const stylifyPlugin = (mangle) => (stylifyVite({
bundles: [{
outputFile: './src/stylify.css',
files: ['./src/**/*.svelte'],
}],
compiler: {
mangleSelectors: mangle
}
}));
let plugins = [
svelte(),
pages(),
];
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
if (mode == "android") {
return {
plugins: [legacy(), ...plugins, stylifyPlugin(false)],
};
} else if (mode == "online") {
return {
plugins: [...plugins, stylifyPlugin(true)],
};
} else {
return {
plugins: [...plugins, stylifyPlugin(false)],
};
}
}); |
Great! I will add this to snippets. Thanks a lot for testing! |
The mangling is now opt-in. For further reading. |
const cssRecordSelector = config.mangledSelector ? this.mangledSelector : this.selector;
-> const cssRecordSelector = config.minimize ? this.mangledSelector : this.selector;
The text was updated successfully, but these errors were encountered: