1

I'm got stuck in this,

if (condition) {
  import("./style1.css");
} else {
  import("./style2.css");
}

When trying to import styling conditionally. It works locally, But when you build the app then both styles combines. And gets conflicts.

Thank you !!!

1 Answer 1

1

Are you using below in your babel configuration.

@babel/plugin-syntax-dynamic-import

you need to configure Babel to transpile your dynamic imports.

Also the Webpack syntax mentions to use it like a promise.

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

2 Comments

Thanks Once Again. No I'm not using @babel/plugin-syntax-dynamic-import. Also I've tried import using promise still not working. Could you explain updation in babel configuration.
Ok, you would need to use this plugin - so that dynamic import works , Here is an article to provide some assistance blog.jscrambler.com/… . If you don't use babel at all then require.ensure is another way. Give the above two a try and let know.

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.