6

I'm starting VueJS, I started my code from the original Vue Loader Example and I tested running npm run dev or npm run build but a question emerge : Is there a way to place all the css from the components in one place (like styles.min.css).

I added bootstrap as dependencies in my package.json and but when I do a npm run build I can only find the build.js file in dist, that's all.

Thank you for your help.

5
  • Why would you want to do that... Vue components, like react components have a way to put all content for a component in one place... if you want to create a single css file.. then just don't use components.. Commented Dec 17, 2015 at 17:02
  • 1
    This doesn't make sense : Even if I use Vue.js component, there is a single build.js file generated. Why it wouldn't do the same for css ? Commented Dec 18, 2015 at 7:57
  • If you check the source for all css in effect for any element, then for the vue component it is just <style></style> and not any other file that you want generated. My point wasn't why it won't do it for you... If you want to have your css in a seperate file, then just create one... what's the problem? There are plenty of build tools for that too.. Commented Dec 18, 2015 at 13:49
  • I believe we are not talking about the same thing. What I want is to merge all the <style></style> inlined in the html page, generated from the *.vue files, in one, external .css file. I'm also sure there is tools for that, hence my question :) Commented Dec 18, 2015 at 13:57
  • QUESTION: Why would you want to do that? ANSWER: IE11 Commented Nov 13, 2019 at 21:49

1 Answer 1

4

There's a plugin for that

npm install extract-text-webpack-plugin --save-dev

and then configure it in your webpack.config.js

var ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
  // other options...
  module: {
    loaders: [
     {
       test: /\.vue$/,
       loader: 'vue'
     },
    ]
  },
  vue: {
    loaders: {
      css: ExtractTextPlugin.extract("css"),
      // you can also include <style lang="less"> or other langauges
      less: ExtractTextPlugin.extract("css!less")
    }
  },
  plugins: [
    new ExtractTextPlugin("style.css")
  ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

I couldn't get this to work with a multiple entry points setup. style.css keeps being overwritten.

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.