├── .gitignore ├── index.js ├── package.json └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | const markLoaderGlobal = (markName) => ( 4 | `; var __markLoaderGlobal = typeof global === 'object' ? global : window;` 5 | ); 6 | 7 | const startMark = (markName) => ( 8 | `;__markLoaderGlobal.performance && __markLoaderGlobal.performance.mark && __markLoaderGlobal.performance.mark('${markName}_start'); ` 9 | ); 10 | 11 | const endMark = (markName) => ( 12 | `;__markLoaderGlobal.performance && __markLoaderGlobal.performance.mark && __markLoaderGlobal.performance.mark('${markName}_end'); ` 13 | ); 14 | 15 | const measure = (markName) => ( 16 | `;__markLoaderGlobal.performance && __markLoaderGlobal.performance.measure && __markLoaderGlobal.performance.measure('${markName}', '${markName}_start', '${markName}_end'); ` 17 | ); 18 | 19 | const markLoader = function markLoader(content) { 20 | const context = this._compiler && this._compiler.context || process.cwd() || ''; 21 | const resourcePath = this.resourcePath; 22 | const markName = path.relative(context, resourcePath).replace(/[^a-zA-Z0-9]/g, '_'); 23 | 24 | return [ 25 | markLoaderGlobal(), 26 | startMark(markName), 27 | content, 28 | endMark(markName), 29 | measure(markName), 30 | ].join(''); 31 | }; 32 | 33 | module.exports = markLoader; 34 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mark-loader", 3 | "version": "0.1.6", 4 | "description": "Inspect module load time with performance.measure", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "webpack", 11 | "loader", 12 | "performance" 13 | ], 14 | "author": "statianzo", 15 | "license": "ISC" 16 | } 17 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # mark-loader 2 | 3 | Inspect module load time using `performance.mark` and `performance.measure`. 4 | This dev time loader is useful for calling out candidates for lazy loading. 5 | 6 | ## Installation 7 | 8 | ``` 9 | npm i -D mark-loader 10 | ``` 11 | 12 | ## Usage 13 | 14 | Add `mark-loader` to your `webpack.config.js` 15 | 16 | ```js 17 | //webpack.config.js 18 | 19 | { 20 | 21 | module.exports = { 22 | //... 23 | module: { 24 | rules: [ 25 | {test: /\.js$/, use: 'mark-loader'} 26 | ] 27 | } 28 | } 29 | 30 | ``` 31 | 32 | Open the Chrome Developer Tools to the Timeline tab and refresh the page. Load 33 | information will show as a flame chart under `User Timing`. 34 | 35 | ## Use only in development 36 | 37 | There is overhead in `performance.mark` and `performance.measure`, so this 38 | loader is not recommended in production builds. 39 | 40 | ## License 41 | 42 | ISC License (ISC) 43 | Copyright 2017 Jason Staten 44 | 45 | Permission to use, copy, modify, and/or distribute this software for any 46 | purpose with or without fee is hereby granted, provided that the above 47 | copyright notice and this permission notice appear in all copies. 48 | 49 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 50 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 51 | FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 52 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 53 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 54 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 55 | PERFORMANCE OF THIS SOFTWARE. 56 | --------------------------------------------------------------------------------