vuejs CLI错误,有很棒的字体

时间:2018-03-28 13:09:16

标签: vuejs2 font-awesome

我正在使用vue CLI webpack setup并通过npm安装了很棒的字体包。在main.js中我输入了字体:

import 'vuetify/dist/vuetify.min.css'

我收到以下错误:

./node_modules/font-awesome/fonts/fontawesome-webfont.ttf?v=4.7.0
Module parse failed: Unexpected character '' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
 @ ./node_modules/css-loader!./node_modules/font-awesome/css/font-awesome.css 7:684-735
 @ ./node_modules/font-awesome/css/font-awesome.css
 @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue
 @ ./src/App.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

并且标准的webpack配置文件: 任何想法如何使用正确的装载机?

问候

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: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader'
        ],
      },      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    },
    extensions: ['*', '.js', '.vue', '.json']
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true
  },
  performance: {
    hints: false
  },
  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({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}

1 个答案:

答案 0 :(得分:1)

您不需要插入vue-style-loader来加载CSS。这是vue-loader使用的内部加载程序。

rules: [
  {
    test: /\.css$/,
    use: [
-     'vue-style-loader',
      'css-loader'
    ],
  },      {

你还需要一个ttf文件加载器:

    {
       test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
       use:[ { loader: "url-loader", options: {limit: 10000, mimetype: 'application/octet-stream'} }]
    },

font-awsome还需要加载woff文件:

    {
        test: /\.woff(2)?(\?v=\d+\.\d+\.\d+)?$/,
        use:[ { loader: "url-loader", options: {limit: 10000, mimetype: 'application/font-woff'} }]
    },