无法解决Vuejs元素ui模板中的scss加载程序

时间:2017-04-22 20:32:24

标签: webpack vue.js vuejs2 webpack-dev-server css-loader

您好我正在尝试为vue js 2使用元素ui模板。我已经按照本指南http://element.eleme.io/#/en-US/component/quickstart但是我收到了一个找不到模块的错误:无法解析文件App.vue中的scss加载程序。这是我的package.json

{
  "name": "testvuejs",
  "description": "A Vue.js project",
  "version": "1.0.0",
  "author": "AbdurRehman <abdurrehman@getperkup.com>",
  "private": true,
  "scripts": {
    "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
    "build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
  },
  "dependencies": {
    "element-ui": "^1.2.9",
    "vue": "^2.2.1"
  },
  "devDependencies": {
    "babel-core": "^6.0.0",
    "babel-loader": "^6.0.0",
    "babel-preset-latest": "^6.0.0",
    "cross-env": "^3.0.0",
    "css-loader": "^0.25.0",
    "file-loader": "^0.9.0",
    "node-sass": "^4.5.2",
    "sass-loader": "^5.0.1",
    "style-loader": "^0.13.1",
    "vue-loader": "^11.1.4",
    "vue-template-compiler": "^2.2.1",
    "webpack": "^2.2.0",
    "webpack-dev-server": "^2.2.0"
  }
}

这是我的webpack.config.js

var path = require('path')
var webpack = require('webpack')

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/dist/',
    filename: 'build.js'
  },
  module: {
    loaders: [
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.css$/,
        loader: 'style-loader!css-loader'
      },
      {
        test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
        loader: 'file-loader'
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?\S*)?$/,
        loader: 'file-loader',
        query: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true
  },
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      }
    })
  ])
}

最后是我的main.js

import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import App from './App.vue'

Vue.use(ElementUI)

new Vue({
      el: '#app',
      render: h => h(App)
})

这是包

的github链接

https://github.com/ElemeFE/element

2 个答案:

答案 0 :(得分:0)

我解决了..似乎我正在使用样式lang = scss,当它实际上不在那里时。

答案 1 :(得分:0)

您可以将scss与您的组件一起使用。 只是做

npm install sass-loader node-sass webpack --save-dev

现在你可以通过

来使用SASS
<style lang="scss" scoped>
</style>