Vue.js + Webpack multiple style tas output

2020-04-16 03:22发布

I have several vue.js components, written in single page component format.

For each .vue file, I have less written specific for that page.

After bundling, I have several style tags, which populate the global style space. Thus, some of my classes are overlapping on different pages.

Head

Is this the intended functionality with vue.js and webpack?

1条回答
啃猪蹄的小仙女
2楼-- · 2020-04-16 03:37

This is the default behaviour for vue-loader (which is the main plugin in the vue-webpack template).

However, if you want to you can extract all CSS into one file:

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

// 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")
  ]
}

Check out the docs of vue-loader regarding extraction.

查看更多
登录 后发表回答