nav tabs on admin dashboard
This commit is contained in:
518
node_modules/webpack-dev-middleware/README.md
generated
vendored
518
node_modules/webpack-dev-middleware/README.md
generated
vendored
@@ -1,3 +1,9 @@
|
||||
<div align="center">
|
||||
<a href="https://github.com/webpack/webpack">
|
||||
<img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
[![npm][npm]][npm-url]
|
||||
[![node][node]][node-url]
|
||||
[![deps][deps]][deps-url]
|
||||
@@ -5,206 +11,429 @@
|
||||
[![coverage][cover]][cover-url]
|
||||
[![chat][chat]][chat-url]
|
||||
|
||||
<div align="center">
|
||||
<a href="https://github.com/webpack/webpack">
|
||||
<img width="200" height="200"
|
||||
src="https://webpack.js.org/assets/icon-square-big.svg">
|
||||
</a>
|
||||
<h1>webpack Dev Middleware</h1>
|
||||
</div>
|
||||
# webpack-dev-middleware
|
||||
|
||||
It's a simple wrapper middleware for webpack. It serves the files emitted from webpack over a connect server. This should be used for **development only**.
|
||||
An express-style development middleware for use with [webpack](https://webpack.js.org)
|
||||
bundles and allows for serving of the files emitted from webpack.
|
||||
This should be used for **development only**.
|
||||
|
||||
It has a few advantages over bundling it as files:
|
||||
Some of the benefits of using this middleware include:
|
||||
|
||||
* No files are written to disk, it handle the files in memory
|
||||
* If files changed in watch mode, the middleware no longer serves the old bundle, but delays requests until the compiling has finished. You don't have to wait before refreshing the page after a file modification.
|
||||
* I may add some specific optimization in future releases.
|
||||
- No files are written to disk, rather it handles files in memory
|
||||
- If files changed in watch mode, the middleware delays requests until compiling
|
||||
has completed.
|
||||
- Supports hot module reload (HMR).
|
||||
|
||||
<h2 align="center">Install</h2>
|
||||
## Requirements
|
||||
|
||||
```
|
||||
This module requires a minimum of Node v6.9.0 and Webpack v4.0.0, and must be used with a
|
||||
server that accepts express-style middleware.
|
||||
|
||||
## Getting Started
|
||||
|
||||
First thing's first, install the module:
|
||||
|
||||
```console
|
||||
npm install webpack-dev-middleware --save-dev
|
||||
```
|
||||
|
||||
<h2 align="center">Usage</h2>
|
||||
_Note: We do not recommend installing this module globally._
|
||||
|
||||
``` javascript
|
||||
var webpackMiddleware = require("webpack-dev-middleware");
|
||||
app.use(webpackMiddleware(...));
|
||||
```
|
||||
## Usage
|
||||
|
||||
Example usage:
|
||||
```js
|
||||
const webpack = require('webpack');
|
||||
const middleware = require('webpack-dev-middleware');
|
||||
const compiler = webpack({ .. webpack options .. });
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
``` javascript
|
||||
app.use(webpackMiddleware(webpack({
|
||||
// webpack options
|
||||
// webpackMiddleware takes a Compiler object as first parameter
|
||||
// which is returned by webpack(...) without callback.
|
||||
entry: "...",
|
||||
output: {
|
||||
path: "/"
|
||||
// no real path is required, just pass "/"
|
||||
// but it will work with other paths too.
|
||||
}
|
||||
}), {
|
||||
// publicPath is required, whereas all other options are optional
|
||||
|
||||
noInfo: false,
|
||||
// display no info to console (only warnings and errors)
|
||||
|
||||
quiet: false,
|
||||
// display nothing to the console
|
||||
|
||||
lazy: true,
|
||||
// switch into lazy mode
|
||||
// that means no watching, but recompilation on every request
|
||||
|
||||
watchOptions: {
|
||||
aggregateTimeout: 300,
|
||||
poll: true
|
||||
},
|
||||
// watch options (only lazy: false)
|
||||
|
||||
publicPath: "/assets/",
|
||||
// public path to bind the middleware to
|
||||
// use the same as in webpack
|
||||
|
||||
index: "index.html",
|
||||
// The index path for web server, defaults to "index.html".
|
||||
// If falsy (but not undefined), the server will not respond to requests to the root URL.
|
||||
|
||||
headers: { "X-Custom-Header": "yes" },
|
||||
// custom headers
|
||||
|
||||
mimeTypes: { "text/html": [ "phtml" ] },
|
||||
// Add custom mime/extension mappings
|
||||
// https://github.com/broofa/node-mime#mimedefine
|
||||
// https://github.com/webpack/webpack-dev-middleware/pull/150
|
||||
|
||||
stats: {
|
||||
colors: true
|
||||
},
|
||||
// options for formating the statistics
|
||||
|
||||
reporter: null,
|
||||
// Provide a custom reporter to change the way how logs are shown.
|
||||
|
||||
serverSideRender: false,
|
||||
// Turn off the server-side rendering mode. See Server-Side Rendering part for more info.
|
||||
app.use(middleware(compiler, {
|
||||
// webpack-dev-middleware options
|
||||
}));
|
||||
|
||||
app.listen(3000, () => console.log('Example app listening on port 3000!'))
|
||||
```
|
||||
|
||||
## Advanced API
|
||||
## Options
|
||||
|
||||
This part shows how you might interact with the middleware during runtime:
|
||||
The middleware accepts an `options` Object. The following is a property reference
|
||||
for the Object.
|
||||
|
||||
* `close(callback)` - stop watching for file changes
|
||||
```js
|
||||
var webpackDevMiddlewareInstance = webpackMiddleware(/* see example usage */);
|
||||
app.use(webpackDevMiddlewareInstance);
|
||||
// After 10 seconds stop watching for file changes:
|
||||
setTimeout(function(){
|
||||
webpackDevMiddlewareInstance.close();
|
||||
}, 10000);
|
||||
```
|
||||
_Note: The `publicPath` property is required, whereas all other options are optional_
|
||||
|
||||
* `invalidate()` - recompile the bundle - e.g. after you changed the configuration
|
||||
```js
|
||||
var compiler = webpack(/* see example usage */);
|
||||
var webpackDevMiddlewareInstance = webpackMiddleware(compiler);
|
||||
app.use(webpackDevMiddlewareInstance);
|
||||
setTimeout(function(){
|
||||
// After a short delay the configuration is changed
|
||||
// in this example we will just add a banner plugin:
|
||||
compiler.apply(new webpack.BannerPlugin('A new banner'));
|
||||
// Recompile the bundle with the banner plugin:
|
||||
webpackDevMiddlewareInstance.invalidate();
|
||||
}, 1000);
|
||||
```
|
||||
### methods
|
||||
|
||||
* `waitUntilValid(callback)` - executes the `callback` if the bundle is valid or after it is valid again:
|
||||
```js
|
||||
var webpackDevMiddlewareInstance = webpackMiddleware(/* see example usage */);
|
||||
app.use(webpackDevMiddlewareInstance);
|
||||
webpackDevMiddlewareInstance.waitUntilValid(function(){
|
||||
console.log('Package is in a valid state');
|
||||
});
|
||||
```
|
||||
Type: `Array`
|
||||
Default: `[ 'GET' ]`
|
||||
|
||||
This property allows a user to pass the list of HTTP request methods accepted by the server.
|
||||
|
||||
### headers
|
||||
|
||||
Type: `Object`
|
||||
Default: `undefined`
|
||||
|
||||
This property allows a user to pass custom HTTP headers on each request. eg.
|
||||
`{ "X-Custom-Header": "yes" }`
|
||||
|
||||
### index
|
||||
|
||||
Type: `String`
|
||||
Default: `undefined`
|
||||
|
||||
"index.html",
|
||||
// The index path for web server, defaults to "index.html".
|
||||
// If falsy (but not undefined), the server will not respond to requests to the root URL.
|
||||
|
||||
|
||||
### lazy
|
||||
|
||||
Type: `Boolean`
|
||||
Default: `undefined`
|
||||
|
||||
This option instructs the module to operate in 'lazy' mode, meaning that it won't
|
||||
recompile when files change, but rather on each request.
|
||||
|
||||
### logger
|
||||
|
||||
Type: `Object`
|
||||
Default: [`webpack-log`](https://github.com/webpack-contrib/webpack-log/blob/master/index.js)
|
||||
|
||||
In the rare event that a user would like to provide a custom logging interface,
|
||||
this property allows the user to assign one. The module leverages
|
||||
[`webpack-log`](https://github.com/webpack-contrib/webpack-log#readme)
|
||||
for creating the [`loglevelnext`](https://github.com/shellscape/loglevelnext#readme)
|
||||
logging management by default. Any custom logger must adhere to the same
|
||||
exports for compatibility. Specifically, all custom loggers must have the
|
||||
following exported methods at a minimum:
|
||||
|
||||
- `log.trace`
|
||||
- `log.debug`
|
||||
- `log.info`
|
||||
- `log.warn`
|
||||
- `log.error`
|
||||
|
||||
Please see the documentation for `loglevel` for more information.
|
||||
|
||||
### logLevel
|
||||
|
||||
Type: `String`
|
||||
Default: `'info'`
|
||||
|
||||
This property defines the level of messages that the module will log. Valid levels
|
||||
include:
|
||||
|
||||
- `trace`
|
||||
- `debug`
|
||||
- `info`
|
||||
- `warn`
|
||||
- `error`
|
||||
- `silent`
|
||||
|
||||
Setting a log level means that all other levels below it will be visible in the
|
||||
console. Setting `logLevel: 'silent'` will hide all console output. The module
|
||||
leverages [`webpack-log`](https://github.com/webpack-contrib/webpack-log#readme)
|
||||
for logging management, and more information can be found on its page.
|
||||
|
||||
### logTime
|
||||
|
||||
Type: `Boolean`
|
||||
Default: `false`
|
||||
|
||||
If `true` the log output of the module will be prefixed by a timestamp in the
|
||||
`HH:mm:ss` format.
|
||||
|
||||
### mimeTypes
|
||||
|
||||
Type: `Object`
|
||||
Default: `null`
|
||||
|
||||
This property allows a user to register custom mime types or extension mappings.
|
||||
eg. `mimeTypes: { 'text/html': [ 'phtml' ] }`.
|
||||
|
||||
By default node-mime will throw an error if you try to map a type to an extension
|
||||
that is already assigned to another type. Passing `force: true` will suppress this behavior
|
||||
(overriding any previous mapping).
|
||||
eg. `mimeTypes: { typeMap: { 'text/html': [ 'phtml' ] } }, force: true }`.
|
||||
|
||||
Please see the documentation for
|
||||
[`node-mime`](https://github.com/broofa/node-mime#mimedefinetypemap-force--false) for more information.
|
||||
|
||||
### publicPath
|
||||
|
||||
Type: `String`
|
||||
_Required_
|
||||
|
||||
The public path that the middleware is bound to. _Best Practice: use the same
|
||||
`publicPath` defined in your webpack config. For more information about
|
||||
`publicPath`, please see
|
||||
[the webpack documentation](https://webpack.js.org/guides/public-path)._
|
||||
|
||||
### reporter
|
||||
|
||||
Type: `Object`
|
||||
Default: `undefined`
|
||||
|
||||
Allows users to provide a custom reporter to handle logging within the module.
|
||||
Please see the [default reporter](/lib/reporter.js)
|
||||
for an example.
|
||||
|
||||
### serverSideRender
|
||||
|
||||
Type: `Boolean`
|
||||
Default: `undefined`
|
||||
|
||||
Instructs the module to enable or disable the server-side rendering mode. Please
|
||||
see [Server-Side Rendering](#server-side-rendering) for more information.
|
||||
|
||||
### stats
|
||||
|
||||
Type: `Object`
|
||||
Default: `{ context: process.cwd() }`
|
||||
|
||||
Options for formatting statistics displayed during and after compile. For more
|
||||
information and property details, please see the
|
||||
[webpack documentation](https://webpack.js.org/configuration/stats/#stats).
|
||||
|
||||
### watchOptions
|
||||
|
||||
Type: `Object`
|
||||
Default: `{ aggregateTimeout: 200 }`
|
||||
|
||||
The module accepts an `Object` containing options for file watching, which is
|
||||
passed directly to the compiler provided. For more information on watch options
|
||||
please see the [webpack documentation](https://webpack.js.org/configuration/watch/#watchoptions)
|
||||
|
||||
### writeToDisk
|
||||
|
||||
Type: `Boolean|Function`
|
||||
Default: `false`
|
||||
|
||||
If `true`, the option will instruct the module to write files to the configured
|
||||
location on disk as specified in your `webpack` config file. _Setting
|
||||
`writeToDisk: true` won't change the behavior of the `webpack-dev-middleware`,
|
||||
and bundle files accessed through the browser will still be served from memory._
|
||||
This option provides the same capabilities as the
|
||||
[`WriteFilePlugin`](https://github.com/gajus/write-file-webpack-plugin/pulls).
|
||||
|
||||
This option also accepts a `Function` value, which can be used to filter which
|
||||
files are written to disk. The function follows the same premise as
|
||||
[`Array#filter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
|
||||
in which a return value of `false` _will not_ write the file, and a return value
|
||||
of `true` _will_ write the file to disk. eg.
|
||||
|
||||
```js
|
||||
{
|
||||
writeToDisk: (filePath) => {
|
||||
return /superman\.css$/.test(filePath);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### fs
|
||||
Type: `Object`
|
||||
Default: `MemoryFileSystem`
|
||||
|
||||
Set the default file system which will be used by webpack as primary destination of generated files. Default is set to webpack's default file system: [memory-fs](https://github.com/webpack/memory-fs). This option isn't affected by the [writeToDisk](#writeToDisk) option.
|
||||
|
||||
**Note:** As of 3.5.x version of the middleware you have to provide `.join()` method to the `fs` instance manually. This can be done simply by using `path.join`:
|
||||
```js
|
||||
fs.join = path.join // no need to bind
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
`webpack-dev-middleware` also provides convenience methods that can be use to
|
||||
interact with the middleware at runtime:
|
||||
|
||||
### `close(callback)`
|
||||
|
||||
Instructs a webpack-dev-middleware instance to stop watching for file changes.
|
||||
|
||||
### Parameters
|
||||
|
||||
#### callback
|
||||
|
||||
Type: `Function`
|
||||
|
||||
A function executed once the middleware has stopped watching.
|
||||
|
||||
### `invalidate()`
|
||||
|
||||
Instructs a webpack-dev-middleware instance to recompile the bundle.
|
||||
e.g. after a change to the configuration.
|
||||
|
||||
```js
|
||||
const webpack = require('webpack');
|
||||
const compiler = webpack({ ... });
|
||||
const middleware = require('webpack-dev-middleware');
|
||||
const instance = middleware(compiler);
|
||||
|
||||
app.use(instance);
|
||||
|
||||
setTimeout(() => {
|
||||
// After a short delay the configuration is changed and a banner plugin is added
|
||||
// to the config
|
||||
compiler.apply(new webpack.BannerPlugin('A new banner'));
|
||||
|
||||
// Recompile the bundle with the banner plugin:
|
||||
instance.invalidate();
|
||||
}, 1000);
|
||||
```
|
||||
|
||||
### `waitUntilValid(callback)`
|
||||
|
||||
Executes a callback function when the compiler bundle is valid, typically after
|
||||
compilation.
|
||||
|
||||
### Parameters
|
||||
|
||||
#### callback
|
||||
|
||||
Type: `Function`
|
||||
|
||||
A function executed when the bundle becomes valid. If the bundle is
|
||||
valid at the time of calling, the callback is executed immediately.
|
||||
|
||||
```js
|
||||
const webpack = require('webpack');
|
||||
const compiler = webpack({ ... });
|
||||
const middleware = require('webpack-dev-middleware');
|
||||
const instance = middleware(compiler);
|
||||
|
||||
app.use(instance);
|
||||
|
||||
instance.waitUntilValid(() => {
|
||||
console.log('Package is in a valid state');
|
||||
});
|
||||
```
|
||||
## Known Issues
|
||||
|
||||
### Multiple Successive Builds
|
||||
|
||||
Watching (by means of `lazy: false`) will frequently cause multiple compilations
|
||||
as the bundle changes during compilation. This is due in part to cross-platform
|
||||
differences in file watchers, so that webpack doesn't loose file changes when
|
||||
watched files change rapidly. If you run into this situation, please make use of
|
||||
the [`TimeFixPlugin`](https://github.com/egoist/time-fix-plugin).
|
||||
|
||||
## Server-Side Rendering
|
||||
|
||||
**Note: this feature is experimental and may be removed or changed completely in the future.**
|
||||
_Note: this feature is experimental and may be removed or changed completely in the future._
|
||||
|
||||
In order to develop a server-side rendering application, we need access to the [`stats`](https://github.com/webpack/docs/wiki/node.js-api#stats), which is generated with the latest build.
|
||||
In order to develop an app using server-side rendering, we need access to the
|
||||
[`stats`](https://github.com/webpack/docs/wiki/node.js-api#stats), which is
|
||||
generated with each build.
|
||||
|
||||
In the server-side rendering mode, __webpack-dev-middleware__ sets the `stat` to `res.locals.webpackStats` before invoking the next middleware, allowing a developer to render the page body and manage the response to clients.
|
||||
With server-side rendering enabled, `webpack-dev-middleware` sets the `stat` to
|
||||
`res.locals.webpackStats` and the memory filesystem to `res.locals.fs` before invoking the next middleware, allowing a
|
||||
developer to render the page body and manage the response to clients.
|
||||
|
||||
Notice that requests for bundle files would still be responded by __webpack-dev-middleware__ and all requests will be pending until the building process is finished in the server-side rendering mode.
|
||||
_Note: Requests for bundle files will still be handled by
|
||||
`webpack-dev-middleware` and all requests will be pending until the build
|
||||
process is finished with server-side rendering enabled._
|
||||
|
||||
Example Implementation:
|
||||
|
||||
```js
|
||||
const webpack = require('webpack');
|
||||
const compiler = webpack({ ... });
|
||||
const isObject = require('is-object');
|
||||
const middleware = require('webpack-dev-middleware');
|
||||
|
||||
```javascript
|
||||
// This function makes server rendering of asset references consistent with different webpack chunk/entry configurations
|
||||
function normalizeAssets(assets) {
|
||||
if (isObject(assets)) {
|
||||
return Object.values(assets)
|
||||
}
|
||||
return Array.isArray(assets) ? assets : [assets]
|
||||
}
|
||||
|
||||
app.use(webpackMiddleware(compiler, { serverSideRender: true })
|
||||
app.use(middleware(compiler, { serverSideRender: true }))
|
||||
|
||||
// The following middleware would not be invoked until the latest build is finished.
|
||||
app.use((req, res) => {
|
||||
|
||||
const assetsByChunkName = res.locals.webpackStats.toJson().assetsByChunkName
|
||||
|
||||
const fs = res.locals.fs
|
||||
const outputPath = res.locals.webpackStats.toJson().outputPath
|
||||
|
||||
// then use `assetsByChunkName` for server-sider rendering
|
||||
// For example, if you have only one main chunk:
|
||||
|
||||
res.send(`
|
||||
res.send(`
|
||||
<html>
|
||||
<head>
|
||||
<title>My App</title>
|
||||
${
|
||||
normalizeAssets(assetsByChunkName.main)
|
||||
.filter(path => path.endsWith('.css'))
|
||||
.map(path => `<link rel="stylesheet" href="${path}" />`)
|
||||
.join('\n')
|
||||
}
|
||||
<style>
|
||||
${normalizeAssets(assetsByChunkName.main)
|
||||
.filter(path => path.endsWith('.css'))
|
||||
.map(path => fs.readFileSync(outputPath + '/' + path))
|
||||
.join('\n')}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
${
|
||||
normalizeAssets(assetsByChunkName.main)
|
||||
.filter(path => path.endsWith('.js'))
|
||||
.map(path => `<script src="${path}"></script>`)
|
||||
.join('\n')
|
||||
}
|
||||
${normalizeAssets(assetsByChunkName.main)
|
||||
.filter(path => path.endsWith('.js'))
|
||||
.map(path => `<script src="${path}"></script>`)
|
||||
.join('\n')}
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
</html>
|
||||
`)
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
<h2 align="center">Contributing</h2>
|
||||
## Support
|
||||
|
||||
Don't hesitate to create a pull request. Every contribution is appreciated. In development you can start the tests by calling `npm test`.
|
||||
We do our best to keep Issues in the repository focused on bugs, features, and
|
||||
needed modifications to the code for the module. Because of that, we ask users
|
||||
with general support, "how-to", or "why isn't this working" questions to try one
|
||||
of the other support channels that are available.
|
||||
|
||||
<h2 align="center">Maintainers</h2>
|
||||
Your first-stop-shop for support for webpack-dev-server should by the excellent
|
||||
[documentation][docs-url] for the module. If you see an opportunity for improvement
|
||||
of those docs, please head over to the [webpack.js.org repo][wjo-url] and open a
|
||||
pull request.
|
||||
|
||||
From there, we encourage users to visit the [webpack Gitter chat][chat-url] and
|
||||
talk to the fine folks there. If your quest for answers comes up dry in chat,
|
||||
head over to [StackOverflow][stack-url] and do a quick search or open a new
|
||||
question. Remember; It's always much easier to answer questions that include your
|
||||
`webpack.config.js` and relevant files!
|
||||
|
||||
If you're twitter-savvy you can tweet [#webpack][hash-url] with your question
|
||||
and someone should be able to reach out and lend a hand.
|
||||
|
||||
If you have discovered a :bug:, have a feature suggestion, of would like to see
|
||||
a modification, please feel free to create an issue on Github. _Note: The issue
|
||||
template isn't optional, so please be sure not to remove it, and please fill it
|
||||
out completely._
|
||||
|
||||
## Contributing
|
||||
|
||||
We welcome your contributions! Please have a read of [CONTRIBUTING.md](CONTRIBUTING.md) for more information on how to get involved.
|
||||
|
||||
## Maintainers
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<img width="150 height="150"
|
||||
src="https://avatars.githubusercontent.com/SpaceK33z?v=3">
|
||||
<img src="https://avatars.githubusercontent.com/SpaceK33z?v=4&s=150">
|
||||
<br />
|
||||
<a href="https://github.com/SpaceK33z">Kees Kluskens</a>
|
||||
</td>
|
||||
<tr>
|
||||
<tbody>
|
||||
<td align="center">
|
||||
<img src="https://i.imgur.com/4v6pgxh.png">
|
||||
<br />
|
||||
<a href="https://github.com/shellscape">Andrew Powell</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<h2 align="center">LICENSE</h2>
|
||||
## License
|
||||
|
||||
#### [MIT](./LICENSE)
|
||||
|
||||
@@ -225,3 +454,10 @@ Don't hesitate to create a pull request. Every contribution is appreciated. In d
|
||||
|
||||
[chat]: https://badges.gitter.im/webpack/webpack.svg
|
||||
[chat-url]: https://gitter.im/webpack/webpack
|
||||
|
||||
[docs-url]: https://webpack.js.org/guides/development/#using-webpack-dev-middleware
|
||||
[hash-url]: https://twitter.com/search?q=webpack
|
||||
[middleware-url]: https://github.com/webpack/webpack-dev-middleware
|
||||
[stack-url]: https://stackoverflow.com/questions/tagged/webpack-dev-middleware
|
||||
[uglify-url]: https://github.com/webpack-contrib/uglifyjs-webpack-plugin
|
||||
[wjo-url]: https://github.com/webpack/webpack.js.org
|
||||
|
||||
Reference in New Issue
Block a user