0

So I have a very small app I've built that I want to integrate into a website as a web component. So I build the app using vue-cli-service build --target wc --inline-vue --name name-of-component

However the SCSS styling is not included? It works fine in the live reload during development. The SCSS file is imported in the main.js file like this:

import Vue from 'vue';
import App from './App.vue';
import store from './store';
import './assets/main.scss';

Vue.config.productionTip = false;

new Vue({
    store,
    render: (h) => h(App),
}).$mount('#app');

2 Answers 2

1

I'm not sure why, but a workaround is to import the SCSS within the <style> block instead of <script>:

<style lang="scss">
@import '~@/assets/main.scss';
</style>
Sign up to request clarification or add additional context in comments.

Comments

1

I found a solution which is a mix of importing like tony19 said:

<style lang="scss">
@import '~@/assets/main.scss';
</style>

Then using sass main.scss main.css and including a <link rel="stylesheet" href="main.css"> in the same document as the web component. That way the styling was applied correctly.

Also generally I would recommend hosting any assets such as css, fonts, images, svgs, etc. etc. on a CDN and using the full url to the asset in the web component so that you don't have to include these on the web pages using the component.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.