DragonsInn / fontgen-loader

Automated webfont generation from SVG icons. Use with WebPack!
125 stars 42 forks source link

ExtractTextPlugin #20

Closed marcelloromanelli closed 8 years ago

marcelloromanelli commented 8 years ago

Hi, I'm trying to extract the generated CSS using the extract-text plugin.

In order to understand what's going on I've setup a simple test project. The webpack.config.js looks like this:

var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var fontgen = require('fontgen-loader');

var cssExtractTextPlugin = new ExtractTextPlugin(1, "style/[name]-[hash].css");

module.exports = {
  entry: "./js/main.js",
  output: {
    path: path.join(__dirname, 'build'),
    filename: 'scripts/[name]-[hash].js',
    // publicPath: '/scripts/'
  },
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: cssExtractTextPlugin.extract("style", "css")
      },
      {
        test: /\.font\.(js|json)$/,
        loader: "style!css!fontgen"
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin(),
    cssExtractTextPlugin
  ]
};

This configuration works perfectly fine and it generates the svg, ttf, eot and woff files. However if I modify the above config and I introduce the extract plugin (see below) I get the follwing error: Module build failed: CssSyntaxError: /css-loader!/Users/marcello/Desktop/webfonts/fonts/tutti.font.js:5:26: Missed semicolon

var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var fontgen = require('fontgen-loader');

var cssExtractTextPlugin = new ExtractTextPlugin(1, "style/[name]-[hash].css");
var fontsExtractTextPlugin = new ExtractTextPlugin(1, "fonts/[name]-[hash].css");

module.exports = {
  entry: "./js/main.js",
  output: {
    path: path.join(__dirname, 'build'),
    filename: 'scripts/[name]-[hash].js',
    // publicPath: '/scripts/'
  },
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: cssExtractTextPlugin.extract("style", "css")
      },
      {
        test: /\.font\.(js|json)$/,
        loader: fontsExtractTextPlugin.extract("style", "css", "fontgen")
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin(),
    cssExtractTextPlugin,
    fontsExtractTextPlugin
  ]
};

Any idea what could be wrong in my setup? I'm fairly new to webpack so forgive me if I'm doing something totally nonsense.

lgringo commented 8 years ago

Hello,

Try with : loader: fontsExtractTextPlugin.extract("style", ["css", "fontgen"])

marcelloromanelli commented 8 years ago

Thanks for the help @lgringo