Skip to content

Compile import css files to javascript when is a customElement #3599

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

Closed
marlonmleite opened this issue Sep 20, 2019 · 2 comments
Closed

Compile import css files to javascript when is a customElement #3599

marlonmleite opened this issue Sep 20, 2019 · 2 comments

Comments

@marlonmleite
Copy link

Problem:
When using external libraries or cssInJs in customElement, we have problems with the scope of shadowDom.

A good feature for svelte/compile:
svelte should would read the file content in the compilation and automatically insert the content into shadowDom.

MySvelte.svelte:

<style>
	@import '/external-file/lib.css';
</style>

Currently, after compilation looks like this (build.js):

    class App$1 extends SvelteElement {
    	constructor(options) {
    		super();

    		this.shadowRoot.innerHTML = `<style>@import '/external-lib.css</style>';

With the new feature (build.js):

    class App$1 extends SvelteElement {
    	constructor(options) {
    		super();

    		this.shadowRoot.innerHTML = `<style>div.class-external-lib {color: red}</style>';
@Conduitry
Copy link
Member

This is outside the purview of Svelte itself, which compiles one component at a time, and doesn't actually access the filesystem at all. Something like this could be implemented with a preprocessor which you pass to the bundler plugin.

@marlonmleite
Copy link
Author

This is outside the purview of Svelte itself, which compiles one component at a time, and doesn't actually access the filesystem at all. Something like this could be implemented with a preprocessor which you pass to the bundler plugin.

@Conduitry I applied the technique using the guidelines of this issue sveltejs/rollup-plugin-svelte#65, but as you can see this does not work very well because of the svelte CSS imposition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants