Repository: unindented/stats-webpack-plugin Branch: master Commit: b3130e5b0740 Files: 14 Total size: 9.7 KB Directory structure: gitextract_2s5z7mdo/ ├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── package.json └── test/ ├── .eslintrc ├── fixtures/ │ ├── entry.js │ └── greeter.js └── plugin.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ # # EditorConfig: http://EditorConfig.org # # This files specifies some basic editor conventions for the files in this # project. Many editors support this standard, you simply need to find a plugin # for your favorite! # # For a full list of possible values consult the reference. # https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties # # Stop searching for other .editorconfig files above this folder. root = true # Pick some sane defaults for all files. [*] # UNIX line-endings are preferred since: # * git prefers them # * servers run on Linux # * most developers use Mac OS X # http://adaptivepatchwork.com/2012/03/01/mind-the-end-of-your-line/ end_of_line = lf # No reason in these modern times to use anything other than UTF-8. charset = utf-8 # Ensure that there's no bogus whitespace in the file. trim_trailing_whitespace = true # A little esoteric, but it's kind of a standard now. # http://stackoverflow.com/questions/729692/why-should-files-end-with-a-newline insert_final_newline = true # Herein be the apex of holy wars. For more information see: # http://programmers.stackexchange.com/questions/57 indent_style = space # Personal preference here. Smaller indent size means you can fit more on a line # which can be nice when there are lines with several indentations. indent_size = 2 # Prefer a more conservative default line length – this allows editors with # sidebars, minimaps, etc. to show at least two documents side-by-side. # Hard wrapping by default for code is useful since many editors don't support # an elegant soft wrap; however, soft wrap is fine for things where text just # flows normally, like Markdown documents or git commit messages. Hard wrap # is also easier for line-based diffing tools to consume. # See: http://tex.stackexchange.com/questions/54140 max_line_length = 80 ================================================ FILE: .eslintignore ================================================ test/fixtures test/output test/new-output node_modules ================================================ FILE: .eslintrc ================================================ { "extends": "standard" } ================================================ FILE: .gitignore ================================================ /node_modules/ /test/output/ /test/new-output/ *.log ================================================ FILE: .npmignore ================================================ /.* /test/ ================================================ FILE: .travis.yml ================================================ language: node_js node_js: - '6' deploy: provider: npm email: unindented@gmail.com api_key: secure: KtlB4jwkf4faKoBWOztL4bQyg7Tqc4fW0zSYefQyr2qsEfz89v7SOEhZQ4Y3npc1EeTLKK0Q3bnKLlsh22TfeJWHid4snSgLmC8H6yGtGBPuGfskKCfAYlVhSr3pbpFeKZyvfJVrLHjq9iE6ks8fdZ/5IIY/fOb1htaMPtPpLAE= on: tags: true ================================================ FILE: LICENSE ================================================ Copyright (c) 2014 Daniel Perez Alvarez Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Stats plugin for webpack [![Version](https://img.shields.io/npm/v/stats-webpack-plugin.svg)](https://www.npmjs.com/package/stats-webpack-plugin) [![Build Status](https://img.shields.io/travis/unindented/stats-webpack-plugin.svg)](http://travis-ci.org/unindented/stats-webpack-plugin) [![Dependency Status](https://img.shields.io/gemnasium/unindented/stats-webpack-plugin.svg)](https://gemnasium.com/unindented/stats-webpack-plugin) Writes the stats of a build to a file. ## Installation ```sh $ npm install --save-dev stats-webpack-plugin ``` ## Usage ```js var StatsPlugin = require('stats-webpack-plugin'); module.exports = { plugins: [ new StatsPlugin('stats.json', { chunkModules: true, exclude: [/node_modules[\\\/]react/] }) ] }; ``` Give webpack the `--profile` flag or set `profile: true` in `webpack.config` to get detailed timing measurements. See [Webpack Profiling](https://webpack.github.io/docs/cli.html#profiling) for more detail. ## API ```js new StatsPlugin(path: string, [options]) ``` * `path`: The path of the result file, relative to your output folder. * `options`: Options passed to [stats.toJson](https://webpack.js.org/api/node/#stats-object) ## Meta * Code: `git clone git://github.com/unindented/stats-webpack-plugin.git` * Home: ## Contributors * Daniel Perez Alvarez ([unindented@gmail.com](mailto:unindented@gmail.com)) * Izaak Schroeder ([izaak.schroeder@gmail.com](mailto:izaak.schroeder@gmail.com)) ## License Copyright (c) 2014 Daniel Perez Alvarez ([unindented.org](https://unindented.org/)). This is free software, and may be redistributed under the terms specified in the LICENSE file. ================================================ FILE: index.js ================================================ var _ = require('lodash') /** * Create a new StatsPlugin that causes webpack to generate a stats file as * part of the emitted assets. * @constructor * @param {String} output Path to output file. * @param {Object} options Options passed to the stats' `.toJson()`. */ function StatsPlugin (output, options, cache) { this.output = output this.options = options this.cache = cache } function onEmit (output, options, cache) { return function (compilation, done) { var result compilation.assets[output] = { size: function getSize () { return result ? result.length : 0 }, source: function getSource () { var stats = compilation.getStats().toJson(options) var result if (cache) { cache = _.merge(cache, stats) if (stats.errors) cache.errors = stats.errors if (stats.warnings) cache.warnings = stats.warnings result = JSON.stringify(cache) } else { result = JSON.stringify(stats) } return result } } done() } } StatsPlugin.prototype.apply = function apply (compiler) { var output = this.output var options = this.options var cache = this.cache var onEmitCallback = onEmit(output, options, cache) if (compiler.hooks) { compiler.hooks.emit.tapAsync('StatsPlugin', onEmitCallback) } else { compiler.plugin('emit', onEmitCallback) } } module.exports = StatsPlugin ================================================ FILE: package.json ================================================ { "name": "stats-webpack-plugin", "description": "Write the stats of a build to a file.", "version": "0.7.0", "license": "MIT", "author": { "name": "Daniel Perez Alvarez", "email": "unindented@gmail.com", "url": "http://unindented.org/" }, "repository": { "type": "git", "url": "git://github.com/unindented/stats-webpack-plugin.git" }, "keywords": [ "stats", "webpack" ], "scripts": { "spec": "mocha", "lint": "eslint .", "test": "npm run lint && npm run spec" }, "peerDependencies": { "webpack": ">=1.0.0" }, "devDependencies": { "chai": "^4.1.2", "eslint": "^4.15.0", "eslint-config-standard": "^10.2.1", "eslint-plugin-import": "^2.8.0", "eslint-plugin-node": "^5.2.1", "eslint-plugin-promise": "^3.6.0", "eslint-plugin-standard": "^3.0.1", "mocha": "^5.0.0", "node-libs-browser": "^2.1.0", "rimraf": "^2.6.2", "webpack": "^3.10.0" }, "dependencies": { "lodash": "^4.17.4" } } ================================================ FILE: test/.eslintrc ================================================ { "env": { "mocha": true } } ================================================ FILE: test/fixtures/entry.js ================================================ var greeter = require('./greeter') console.log(greeter.greet('Daniel')) ================================================ FILE: test/fixtures/greeter.js ================================================ module.exports = { greet: function (name) { return 'Hello ' + name } } ================================================ FILE: test/plugin.js ================================================ var fs = require('fs') var path = require('path') var rimraf = require('rimraf') var webpack = require('webpack') var StatsPlugin = require('../') var chai = require('chai') var expect = chai.expect var inputFolder = path.resolve(__dirname, 'fixtures') var inputFile = path.resolve(inputFolder, 'entry.js') var outputFolder = path.resolve(__dirname, 'output') var outputFile = path.resolve(outputFolder, 'stats.json') var options = { chunkModules: true, exclude: [/node_modules[\\/]/] } var defaultCompilerOptions = { entry: inputFile, output: { path: outputFolder, filename: 'bundle.js' }, profile: true, plugins: [ new StatsPlugin('stats.json', options) ] } var multiCompilerOptions = (cache) => [{ entry: { file1: inputFile }, output: { path: outputFolder, filename: 'bundle1.js' }, profile: true, plugins: [ new StatsPlugin('stats.json', options, cache) ] }, { entry: { file2: inputFile }, output: { path: outputFolder, filename: 'bundle2.js' }, profile: true, plugins: [ new StatsPlugin('stats.json', options, cache) ] }] describe('StatsWebpackPlugin', function () { beforeEach(function () { rimraf.sync(outputFolder) }) it('generates `stats.json` file', function (done) { var compiler = webpack(defaultCompilerOptions) compiler.run(function (err, stats) { if (err) { return done(err) } var actual = JSON.parse(fs.readFileSync(outputFile, 'utf8')) var expected = stats.toJson(options) expect(actual.assets.length).to.equal(expected.assets.length) done() }) }) it('supports multi-compile mode and outputs one `stats.json` file', function (done) { var cache = {} var compiler = webpack(multiCompilerOptions(cache)) compiler.run(function (err, stats) { if (err) { return done(err) } var actual = JSON.parse(fs.readFileSync(outputFile, 'utf8')) var expectedAssetsByChunkName = { file1: 'bundle1.js', file2: 'bundle2.js' } expect(actual.assetsByChunkName).to.deep.equal(expectedAssetsByChunkName) done() }) }) })