1

Following code-splitting recommendations from Webpack and vue-router, I am lazy loading heavy pages in my routes using dynamic import as such:

const Login = () => import("../views/Login/Login.vue");

However if this login.vue page contains an import statement for a css, the style is not properly loaded.

<script>
import '@/assets/sass/my_login.scss'
...

If I remove the dynamic import of the Login.vue page in my routes such as

import Login from '../views/Login/Login.vue'

The css is correctly loaded.

I want to load this Vue page asyncly by using dynamic import and I don't want to make this css global as it is only needed by this specific page.

How am I loading properly this css? Is there some magic syntax to be used in the Login.vue page or in the routes?

Thank your for your help

S.

3
  • Are you using any project templates, or did you create your own project's webpack config? Commented Apr 12, 2018 at 0:38
  • I use a template based on the latest vue-cli Commented Apr 12, 2018 at 1:49
  • Then why don't you use the vue single file component script tag, instead of trying to import it separately? vuejs.org/v2/guide/single-file-components.html Commented Apr 13, 2018 at 1:44

1 Answer 1

1

If you dont want global styles, you can write scope styles in your components. Have u tried this?

<style scoped>

(in your *.vue files)

Sign up to request clarification or add additional context in comments.

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.