Gathering detailed insights and metrics for yhtml5-dev-utils
Gathering detailed insights and metrics for yhtml5-dev-utils
Gathering detailed insights and metrics for yhtml5-dev-utils
Gathering detailed insights and metrics for yhtml5-dev-utils
npm install yhtml5-dev-utils
Typescript
Module System
Min. Node Version
Node Version
NPM Version
52
Supply Chain
87.4
Quality
71.1
Maintenance
25
Vulnerability
98.8
License
Total Downloads
2,595
Last Day
1
Last Week
11
Last Month
23
Last Year
203
Minified
Minified + Gzipped
Latest Version
1.1.9
Package Id
yhtml5-dev-utils@1.1.9
Unpacked Size
26.77 kB
Size
8.30 kB
File Count
11
NPM Version
5.8.0
Node Version
8.9.4
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
0%
11
Compared to previous week
Last Month
-37.8%
23
Compared to previous month
Last Year
16%
203
Compared to previous year
This package includes some utilities used for scaffolding node projects base on Create React App.
Please refer to its documentation:
These utilities come by default with Create React App, which includes it by default. You don’t need to install it separately in Create React App projects.
If you don’t use Create React App, or if you ejected, you may keep using these utilities. Their development will be aligned with Create React App, so major versions of these utilities may come out relatively often. Feel free to fork or copy and paste them into your projects if you’d like to have more control over them, or feel free to use the old versions. Not all of them are React-specific, but we might make some of them more React-specific in the future.
There is no single entry point. You can only import individual top-level modules.
new InterpolateHtmlPlugin(replacements: {[key:string]: string})
This Webpack plugin lets us interpolate custom variables into index.html
.
It works in tandem with HtmlWebpackPlugin 2.x via its events.
1var path = require('path'); 2var HtmlWebpackPlugin = require('html-dev-plugin'); 3var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); 4 5// Webpack config 6var publicUrl = '/my-custom-url'; 7 8module.exports = { 9 output: { 10 // ... 11 publicPath: publicUrl + '/' 12 }, 13 // ... 14 plugins: [ 15 // Makes the public URL available as %PUBLIC_URL% in index.html, e.g.: 16 // <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> 17 new InterpolateHtmlPlugin({ 18 PUBLIC_URL: publicUrl 19 // You can pass any key-value pairs, this was just an example. 20 // WHATEVER: 42 will replace %WHATEVER% with 42 in index.html. 21 }), 22 // Generates an `index.html` file with the <script> injected. 23 new HtmlWebpackPlugin({ 24 inject: true, 25 template: path.resolve('public/index.html'), 26 }), 27 // ... 28 ], 29 // ... 30}
new ModuleScopePlugin(appSrc: string, allowedFiles?: string[])
This Webpack plugin ensures that relative imports from app's source directory don't reach outside of it.
1var path = require('path'); 2var ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin'); 3 4 5module.exports = { 6 // ... 7 resolve: { 8 // ... 9 plugins: [ 10 new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]), 11 // ... 12 ], 13 // ... 14 }, 15 // ... 16}
new WatchMissingNodeModulesPlugin(nodeModulesPath: string)
This Webpack plugin ensures npm install <library>
forces a project rebuild.
We’re not sure why this isn't Webpack's default behavior.
See #186 for details.
1var path = require('path'); 2var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin'); 3 4// Webpack config 5module.exports = { 6 // ... 7 plugins: [ 8 // ... 9 // If you require a missing module and then `npm install` it, you still have 10 // to restart the development server for Webpack to discover it. This plugin 11 // makes the discovery automatic so you don't have to restart. 12 // See https://github.com/facebookincubator/create-react-app/issues/186 13 new WatchMissingNodeModulesPlugin(path.resolve('node_modules')) 14 ], 15 // ... 16}
checkRequiredFiles(files: Array<string>): boolean
Makes sure that all passed files exist.
Filenames are expected to be absolute.
If a file is not found, prints a warning message and returns false
.
1var path = require('path'); 2var checkRequiredFiles = require('react-dev-utils/checkRequiredFiles'); 3 4if (!checkRequiredFiles([ 5 path.resolve('public/index.html'), 6 path.resolve('src/index.js') 7])) { 8 process.exit(1); 9}
clearConsole(): void
Clears the console, hopefully in a cross-platform way.
1var clearConsole = require('react-dev-utils/clearConsole'); 2 3clearConsole(); 4console.log('Just cleared the screen!');
eslintFormatter(results: Object): string
This is our custom ESLint formatter that integrates well with Create React App console output.
You can use the default one instead if you prefer so.
1const eslintFormatter = require('react-dev-utils/eslintFormatter'); 2 3// In your webpack config: 4// ... 5module: { 6 rules: [ 7 { 8 test: /\.(js|jsx)$/, 9 include: paths.appSrc, 10 enforce: 'pre', 11 use: [ 12 { 13 loader: 'eslint-loader', 14 options: { 15 // Pass the formatter: 16 formatter: eslintFormatter, 17 }, 18 }, 19 ], 20 } 21 ] 22}
FileSizeReporter
measureFileSizesBeforeBuild(buildFolder: string): Promise<OpaqueFileSizes>
Captures JS and CSS asset sizes inside the passed buildFolder
. Save the result value to compare it after the build.
printFileSizesAfterBuild(webpackStats: WebpackStats, previousFileSizes: OpaqueFileSizes, buildFolder: string, maxBundleGzipSize?: number, maxChunkGzipSize?: number)
Prints the JS and CSS asset sizes after the build, and includes a size comparison with previousFileSizes
that were captured earlier using measureFileSizesBeforeBuild()
. maxBundleGzipSize
and maxChunkGzipSizemay
may optionally be specified to display a warning when the main bundle or a chunk exceeds the specified size (in bytes).
1var { 2 measureFileSizesBeforeBuild, 3 printFileSizesAfterBuild, 4} = require('react-dev-utils/FileSizeReporter'); 5 6measureFileSizesBeforeBuild(buildFolder).then(previousFileSizes => { 7 return cleanAndRebuild().then(webpackStats => { 8 printFileSizesAfterBuild(webpackStats, previousFileSizes, buildFolder); 9 }); 10});
formatWebpackMessages({errors: Array<string>, warnings: Array<string>}): {errors: Array<string>, warnings: Array<string>}
Extracts and prettifies warning and error messages from webpack stats object.
1var webpack = require('webpack'); 2var config = require('../config/webpack.config.dev'); 3var formatWebpackMessages = require('react-dev-utils/formatWebpackMessages'); 4 5var compiler = webpack(config); 6 7compiler.plugin('invalid', function() { 8 console.log('Compiling...'); 9}); 10 11compiler.plugin('done', function(stats) { 12 var rawMessages = stats.toJson({}, true); 13 var messages = formatWebpackMessages(rawMessages); 14 if (!messages.errors.length && !messages.warnings.length) { 15 console.log('Compiled successfully!'); 16 } 17 if (messages.errors.length) { 18 console.log('Failed to compile.'); 19 messages.errors.forEach(e => console.log(e)); 20 return; 21 } 22 if (messages.warnings.length) { 23 console.log('Compiled with warnings.'); 24 messages.warnings.forEach(w => console.log(w)); 25 } 26});
printBuildError(error: Object): void
Prettify some known build errors. Pass an Error object to log a prettified error message in the console.
const printBuildError = require('react-dev-utils/printBuildError')
try {
build()
} catch(e) {
printBuildError(e) // logs prettified message
}
getProcessForPort(port: number): string
Finds the currently running process on port
.
Returns a string containing the name and directory, e.g.,
create-react-app
in /Users/developer/create-react-app
1var getProcessForPort = require('react-dev-utils/getProcessForPort'); 2 3getProcessForPort(3000);
launchEditor(fileName: string, lineNumber: number): void
On macOS, tries to find a known running editor process and opens the file in it. It can also be explicitly configured by REACT_EDITOR
, VISUAL
, or EDITOR
environment variables. For example, you can put REACT_EDITOR=atom
in your .env.local
file, and Create React App will respect that.
noopServiceWorkerMiddleware(): ExpressMiddleware
Returns Express middleware that serves a /service-worker.js
that resets any previously set service worker configuration. Useful for development.
openBrowser(url: string): boolean
Attempts to open the browser with a given URL.
On Mac OS X, attempts to reuse an existing Chrome tab via AppleScript.
Otherwise, falls back to opn behavior.
1var path = require('path'); 2var openBrowser = require('react-dev-utils/openBrowser'); 3 4if (openBrowser('http://localhost:3000')) { 5 console.log('The browser tab has been opened!'); 6}
printHostingInstructions(appPackage: Object, publicUrl: string, publicPath: string, buildFolder: string, useYarn: boolean): void
Prints hosting instructions after the project is built.
Pass your parsed package.json
object as appPackage
, your the URL where you plan to host the app as publicUrl
, output.publicPath
from your Webpack configuration as publicPath
, the buildFolder
name, and whether to useYarn
in instructions.
1const appPackage = require(paths.appPackageJson); 2const publicUrl = paths.publicUrl; 3const publicPath = config.output.publicPath; 4printHostingInstructions(appPackage, publicUrl, publicPath, 'build', true);
WebpackDevServerUtils
choosePort(host: string, defaultPort: number): Promise<number | null>
Returns a Promise resolving to either defaultPort
or next available port if the user confirms it is okay to do. If the port is taken and the user has refused to use another port, or if the terminal is not interactive and can’t present user with the choice, resolves to null
.
createCompiler(webpack: Function, config: Object, appName: string, urls: Object, useYarn: boolean): WebpackCompiler
Creates a Webpack compiler instance for WebpackDevServer with built-in helpful messages. Takes the require('webpack')
entry point as the first argument. To provide the urls
argument, use prepareUrls()
described below.
prepareProxy(proxySetting: string, appPublicFolder: string): Object
Creates a WebpackDevServer proxy
configuration object from the proxy
setting in package.json
.
prepareUrls(protocol: string, host: string, port: number): Object
Returns an object with local and remote URLs for the development server. Pass this object to createCompiler()
described above.
webpackHotDevClient
This is an alternative client for WebpackDevServer that shows a syntax error overlay.
It currently supports only Webpack 3.x.
1// Webpack development config 2module.exports = { 3 // ... 4 entry: [ 5 // You can replace the line below with these two lines if you prefer the 6 // stock client: 7 // require.resolve('webpack-dev-server/client') + '?/', 8 // require.resolve('webpack/hot/dev-server'), 9 'react-dev-utils/webpackHotDevClient', 10 'src/index' 11 ], 12 // ... 13}
No vulnerabilities found.
No security vulnerabilities found.