ff-stream-web

git clone git://archive.git.mtrnord.blog/MTRNord/ff-stream-web.git
Log | Files | Refs | README | LICENSE

commit 4bd3f3fdaf067842c49af1ce5b2e3188066e7d17
parent 7bbe94c2508203b7a941120ea6a63d9fcf2fc837
Author: Pavel Lang <langpavel@phpskelet.org>
Date:   Tue, 14 Feb 2017 01:17:58 +0100

Generate stats.json for Webpack Analyser (http://webpack.github.io/analyse/)

[closes #790]

Diffstat:
M.gitignore | 1+
Mpackage.json | 3++-
Atools/stats.js | 47+++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore @@ -6,3 +6,4 @@ database.sqlite node_modules ncp-debug.log npm-debug.log +stats.json diff --git a/package.json b/package.json @@ -208,6 +208,7 @@ "deploy": "babel-node tools/run deploy", "render": "babel-node tools/run render", "serve": "babel-node tools/run runServer", - "start": "babel-node tools/run start" + "start": "babel-node tools/run start", + "stats": "babel-node tools/run stats" } } diff --git a/tools/stats.js b/tools/stats.js @@ -0,0 +1,47 @@ +/** + * React Starter Kit (https://www.reactstarterkit.com/) + * + * Copyright © 2014-present Kriasoft, LLC. All rights reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE.txt file in the root directory of this source tree. + */ + +import webpack from 'webpack'; +import { writeFile } from 'fs'; +import { open } from 'openurl'; +import webpackConfig from './webpack.config'; + +const WEBPACK_ANALYSER_URL = 'http://webpack.github.io/analyse/'; +/** + * Creates application stats for client bundle. + */ +function clientStats() { + return new Promise((resolve, reject) => { + const clientConfig = { + ...webpackConfig[0], + profile: true, + }; + + webpack(clientConfig).run((err, stats) => { + if (err) { + reject(err); + return; + } + + const statsJson = JSON.stringify(stats.toJson(), null, 2); + writeFile('stats.json', statsJson, 'utf-8', (saveErr) => { + if (saveErr) { + console.error(saveErr.message); + reject(saveErr); + return; + } + console.log(`Now you can load \`stats.json\` into page at ${WEBPACK_ANALYSER_URL}`); + open(WEBPACK_ANALYSER_URL); + resolve(stats); + }); + }); + }); +} + +export default clientStats;