vue-cli执行run build报错 ?

在vue代码加入<style>...</style>后 run build的时候报错

ERROR in ./~/.npminstall/extract-text-webpack-plugin/1.0.1/extract-text-webpack-
plugin/loader.js?{"omit":1,"extract":true,"remove":true}!./~/.npminstall/vue-sty
le-loader/1.0.0/vue-style-loader!./~/.npminstall/css-loader/0.23.1/css-loader?so
urceMap!./~/.npminstall/vue-loader/8.3.1/vue-loader/lib/style-rewriter.js!./~/.n
pminstall/vue-loader/8.3.1/vue-loader/lib/selector.js?type=style&index=0!./src/v
iews/Index.vue
Module build failed: Error: "extract-text-webpack-plugin" loader is used without
 the corresponding plugin, refer to https://github.com/webpack/extract-text-webp
ack-plugin for the usage example
    at Object.module.exports.pitch (D:\lwl\mydevcode\devtest\vuejs\project\node_
modules\.npminstall\extract-text-webpack-plugin\1.0.1\extract-text-webpack-plugi
n\loader.js:21:9)
 @ ./src/views/Index.vue 2:0-346

这是我github上的代码,运行run build的时候有同样的问题
https://github.com/hofa/vue-st

阅读 8.2k
2 个回答
✓ 已被采纳新手上路,请多包涵

我不知道你的webpack.config.js是怎么配的,当vue单文件组件想把style提取出单独文件中,需要如下手段:

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

module.exports = {
  // other options...
  module: {
    loaders: [
      {
        test: /\.vue$/,
        loader: 'vue'
      },
    ]
  },
  vue: {
    loaders: {
      css: ExtractTextPlugin.extract("css")
    }
  },
  plugins: [
    new ExtractTextPlugin("style.css")
  ]
}

你是这么配置的么?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题