1

I generate a default project with vue-cli:

vue init webpack-simple grid-prototype

I install FontAwesome through npm:

npm install --save fontawesome

After that, I include it into main.js with:

import 'font-awesome/css/font-awesome.css'

I execute the app with:

npm run dev

And I get this error:

Failed to compile.

./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
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8082 webpack/hot/dev-server ./src/main.js

Here's my webpack.config.js (it's the default one created by the cli):

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
    })
  ]);
}

What am I doing wrong?

1

1 Answer 1

2

webpack-simple is suitable for quick prototyping and it doesn't have advanced rules.

Solution #1: Use webpack template instead of webpack-simple to avoid this and other issues in the future.

Solution #2: Use FontAwesome from CDN, for example: https://www.bootstrapcdn.com/fontawesome/

I mean, just add the CDN css to your index.html

Solution #3: Add one more rule to your webpack config

module: {
  rules: [
   {
      test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
      loader: 'url-loader',
      options: {
        limit: 10000,
        name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
      }
   }
 ]

As it is in the webpack template:

https://github.com/vuejs-templates/webpack/blob/develop/template/build/webpack.base.conf.js

Sign up to request clarification or add additional context in comments.

2 Comments

I'm trying #3, but it gives me an error saying utils is not defined. Where is it?
@amedina Investigate webpack template there is utils defined in another place

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.