Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

empty stats.json #9

Closed
opportunato opened this issue Oct 12, 2015 · 5 comments
Closed

empty stats.json #9

opportunato opened this issue Oct 12, 2015 · 5 comments

Comments

@opportunato
Copy link

Hi!

I am using 1.0.0 version, and at the end of the build process I am getting empty stats.json.

How possibly can I debug it and get the cause?

My config looks like this:

require("babel/register");

var path = require("path");
var webpack = require("webpack");
var StatsWriterPlugin = require("webpack-stats-plugin").StatsWriterPlugin;
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var strip = require("strip-loader");

var dist = path.resolve(__dirname, "../static/dist");

module.exports = {
  devtool: "source-map",
  entry: "./src/client.js",
  output: {
    path: dist,
    filename: "[name]-[hash].js",
    chunkFilename: "[name]-[chunkhash].js",
    publicPath: "/dist/"
  },
  module: {
    loaders: [
      { test: /\.(jpe?g|png|gif|svg)$/, loader: "file" },
      { test: /\.(woff|woff2|eot|ttf)$/, loader: 'url-loader?limit=10000' },
      { test: /\.js$/, exclude: /node_modules/, loaders: [strip.loader("debug"), "babel"] },
      { test: /\.scss$/, loader: ExtractTextPlugin.extract("style", "css!autoprefixer?browsers=last 2 version!sass") }
    ]
  },
  plugins: [

    // css files from the extract-text-plugin loader
    new ExtractTextPlugin("[name]-[chunkhash].css"),

    // ignore dev config
    new webpack.IgnorePlugin(/\.\/dev/, /\/config$/),

    // set global vars
    new webpack.DefinePlugin({
      "process.env": {

        // Mainly used to require CSS files with webpack, which can happen only on browser
        // Used as `if (process.env.BROWSER)...`
        BROWSER: JSON.stringify(true),

        // Useful to reduce the size of client-side libraries, e.g. react
        NODE_ENV: JSON.stringify("production")

      }
    }),

    // optimizations
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
          warnings: false
        }
    }),

    // Write out stats.json file to build directory.
    new StatsWriterPlugin({
      transform: function (data) {
        return {
          main: data.assetsByChunkName.main[0],
          css: data.assetsByChunkName.main[1]
        };
      }
    })

  ]
};
@ryan-roemer
Copy link
Member

Hi @opportunato

Can you perhaps point me to a branch that has the empty output issue if your project is open source?

If not, let's look at what the stats object actually looks like. Add a console log like this:

    // Write out stats.json file to build directory.
    new StatsWriterPlugin({
      transform: function (data) {
        console.log("TODO HERE DATA", JSON.stringify(data, null, 2));
        return {
          main: data.assetsByChunkName.main[0],
          css: data.assetsByChunkName.main[1]
        };
      }
    })

and we can debug it further from there...

@opportunato
Copy link
Author

Hi @ryan-roemer, thanks for an amazingly quick answer!

And here is my data:

{
  "assetsByChunkName": {
    "main": [
      "main-5eb780ded6f21bd481ec.js",
      "main-3a98255d560d8afd940c.css",
      "main-5eb780ded6f21bd481ec.js.map",
      "main-3a98255d560d8afd940c.css.map"
    ],
    "locale-it": [
      "locale-it-ce1c63b51b59732ae643.js",
      "locale-it-ce1c63b51b59732ae643.js.map"
    ],
    "locale-en": [
      "locale-en-5579cdff075f45594fc7.js",
      "locale-en-5579cdff075f45594fc7.js.map"
    ],
    "intl": [
      "intl-61d94b94653a1b8ee61b.js",
      "intl-61d94b94653a1b8ee61b.js.map"
    ]
  }
}

@ryan-roemer
Copy link
Member

@opportunato -- can you try the following?

  1. Update to v0.1.1
  2. Change your transform function like this:
    // Write out stats.json file to build directory.
    new StatsWriterPlugin({
      transform: function (data) {
        return JSON.stringify({
          main: data.assetsByChunkName.main[0],
          css: data.assetsByChunkName.main[1]
        }, null, 2);
      }
    })

and let me know how that goes?

@opportunato
Copy link
Author

Now everything works.

Thank you very much, should have checked out the documentation more thoroughly!

@ryan-roemer
Copy link
Member

No worries, and glad that was the issue! The update to v0.1.1 which no longer automatically stringified transform results has been biting other folks too (see #8).

So I just updated the documentation with a bigger, badder warning about needing to return String (07bfbb2)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants