diff options
Diffstat (limited to 'node_modules/koa-webpack')
| -rw-r--r-- | node_modules/koa-webpack/.eslintrc | 10 | ||||
| -rw-r--r-- | node_modules/koa-webpack/.github/ISSUE_TEMPLATE.md | 27 | ||||
| -rw-r--r-- | node_modules/koa-webpack/.travis.yml | 16 | ||||
| -rw-r--r-- | node_modules/koa-webpack/CONTRIBUTING.md | 26 | ||||
| -rw-r--r-- | node_modules/koa-webpack/LICENSE | 21 | ||||
| -rw-r--r-- | node_modules/koa-webpack/README.md | 171 | ||||
| -rwxr-xr-x | node_modules/koa-webpack/index.js | 95 | ||||
| l--------- | node_modules/koa-webpack/node_modules/.bin/webpack | 1 | ||||
| -rw-r--r-- | node_modules/koa-webpack/package.json | 48 | ||||
| -rw-r--r-- | node_modules/koa-webpack/test/fixtures/input.js | 3 | ||||
| -rw-r--r-- | node_modules/koa-webpack/test/results.js | 159 | ||||
| -rw-r--r-- | node_modules/koa-webpack/test/test.js | 20 |
12 files changed, 597 insertions, 0 deletions
diff --git a/node_modules/koa-webpack/.eslintrc b/node_modules/koa-webpack/.eslintrc new file mode 100644 index 00000000..9198b8bf --- /dev/null +++ b/node_modules/koa-webpack/.eslintrc @@ -0,0 +1,10 @@ +{ + "extends": "webpack", + "parserOptions": { + "sourceType": "script" + }, + "rules": { + "comma-dangle": ["error", "never"], + "strict": ["error", "safe"] + } +} diff --git a/node_modules/koa-webpack/.github/ISSUE_TEMPLATE.md b/node_modules/koa-webpack/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..e8fbfb47 --- /dev/null +++ b/node_modules/koa-webpack/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,27 @@ +> The Issues page for this repository is not a support forum, it is for reporting potential bugs in this module, which +[composes](https://github.com/koajs/compose) webpack-hot-middleware and webpack-dev-middle for use with koa2. +If you have arrived here because you cannot get [webpack-hot-middleware](https://github.com/glenjamin/webpack-hot-middlewar) +or [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware/) working, please review the documentation +for the respective middleware you are experiencing a problem with. If you proceed with this form, please fill out *_all_* fields, or your issue may be closed as "invalid." Please remove this header to acknowledge this message. + +* Node Version: +* NPM Version: +* koa Version: +* koa-wepback Version: + +If you have a large amount of code to share which demonstrates the problem you're experiencing, please provide a link to your +repository rather than pasting code. Otherwise, please paste relevant short snippets below. + +```js +// webpack.config.js +``` + +```js +// app.js +``` + +### Expected Behavior + +### Actual Behavior + +### How can we reproduce the behavior? diff --git a/node_modules/koa-webpack/.travis.yml b/node_modules/koa-webpack/.travis.yml new file mode 100644 index 00000000..6282289f --- /dev/null +++ b/node_modules/koa-webpack/.travis.yml @@ -0,0 +1,16 @@ +sudo: false +language: node_js +node_js: + - 9 + - 8 + - 6 + +before_script: + - node --version + - npm --version + +script: + - npm run ci + +matrix: + fast_finish: true diff --git a/node_modules/koa-webpack/CONTRIBUTING.md b/node_modules/koa-webpack/CONTRIBUTING.md new file mode 100644 index 00000000..24cd430b --- /dev/null +++ b/node_modules/koa-webpack/CONTRIBUTING.md @@ -0,0 +1,26 @@ +# Welcome! +> Thanks ahead for taking the time to contribute to this project + +## What We Use + +- Testing: [Mocha](https://mochajs.org/) +- Linting: [ESLint](http://eslint.org/) +- ES6 Transpiling: [Babel](http://babeljs.io/) +- Building: [Webpack](https://webpack.github.io/) + +## Pull Requests + +Please don't commit `package-lock.json`. + +Please don't change variable or parameter names to match your +personal prefrences, unless the change is part of a refactor +or significant modification of the codebase (which is very rare). + +Please remember to thoroughly explain your Pull Request if it +doesn't have an associated issue. If you're changing code +significantly, please remember to add inline or block comments +in the code as appropriate. + +## Thanks + +For your interest, understanding, and for following this simple guide. diff --git a/node_modules/koa-webpack/LICENSE b/node_modules/koa-webpack/LICENSE new file mode 100644 index 00000000..91d8ae8f --- /dev/null +++ b/node_modules/koa-webpack/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Andrew Powell + +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. diff --git a/node_modules/koa-webpack/README.md b/node_modules/koa-webpack/README.md new file mode 100644 index 00000000..a0257f94 --- /dev/null +++ b/node_modules/koa-webpack/README.md @@ -0,0 +1,171 @@ +# koa-webpack [](https://travis-ci.org/shellscape/koa-webpack) + +Development and Hot Module Reload Middleware for **Koa2**, in a single middleware module. + +This module wraps and composes +[`webpack-dev-middleware`](https://github.com/webpack/webpack-dev-middleware) and +[`webpack-hot-client`](https://github.com/webpack-contrib/webpack-hot-client) +into a single middleware module, allowing for quick and concise implementation. + +As an added bonus, it'll also use the installed `webpack` module from your project, +and the `webpack.config.js` file in the root of your project, automagically, should +you choose to let it. This negates the need for all of the repetitive setup and +config that you get with `koa-webpack-middleware`. + +## Version 2 Breaking Changes + +As of version 2.0.0, Node v4 is no longer supported. The minimum version of Node +supported is v6.11. Browser support is limited to those browsers which support +_native_ `WebSocket`. That typically means the last two major versions of a +browser. If you need support for older browsers, please use version 1.x of this +module. If you would like to submit a fix for a 1.x version of the module, please +submit that to the `1.x` branch. + +### Migrating to Version 2.x + +Version 1.x leveraged webpack-hot-middleware, which required the user to add an entry to the config for `webpack-hot-middleware/client`, and also add `webpack.HotModuleReplacementPlugin` to plugins. These are no longer needed, and will cause errors if not removed from the webpack config. + +If you have setup `hot` options for `koa-webpack` in your config or code, you'll need to reference the [`webpack-hot-client` options](https://github.com/webpack-contrib/webpack-hot-client#options) and update those accordingly. The options for `webpack-hot-middleware` are _not_ 1:1 with `webpack-hot-client` + +## Getting Started + +First thing's first, install the module: + +```bash +npm install koa-webpack --save-dev +``` + +If you happen to see warning from npm that reads: +`UNMET PEER DEPENDENCY webpack@2.1.0-beta.25` fear not, simply install the latest +beta version of `webpack`. + +Next, setup the module in your code. (We're assuming ES6 syntax here) + +```js +import Koa from 'koa'; +import middleware from 'koa-webpack'; + +const app = new Koa(); + +app.use(middleware({ + // options +})) +``` + +## API + +### koaWebpack([options]) + +Returns an `Object` containing: + +- `close(callback)` *(Function)* - Closes both the instance of `webpack-dev-middleware` +and `webpack-hot-client`. Accepts a single `Function` callback parameter that is +executed when complete. +- `client` *(Object)* - An instance of `webpack-hot-client`. +- `dev` *(Object)* - An instance of `webpack-dev-middleware` + +## options + +The middleware accepts an `options` Object, which can contain options for the +`webpack-dev-middleware` and `webpack-hot-client` bundled with this module. +The following is a property reference for the Object: + +#### compiler + +Type: `Object` +`optional` + +Should you rather that the middleware use an instance of `webpack` that you've +already init'd [with webpack config], you can pass it to the middleware using +this option. + +Example: + +```js +import Webpack from 'webpack'; +import config from './webpack.config.js'; + +const compiler = Webpack(config); + +app.use(middleware({ + compiler: compiler +})) +``` + +#### config + +Type: `Object` +`optional` + +Should you rather that the middleware use an instance of webpack configuration +that you've already required/imported, you can pass it to the middleware using +this option. + +Example: + +```js +import config from './webpack.config.js'; + +app.use(middleware({ + config: config +})) +``` + +#### dev + +Type: `Object` +`optional` + +The `dev` property should contain options for `webpack-dev-middleware`, a list of +which is available at [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware). +Omitting this property will result in `webpack-dev-middleware` using its default +options. + +#### hot + +Type: `Object|Boolean` +`optional` + +The `hot` property should contain options for `webpack-hot-client`, a list of +which is available at [webpack-hot-client](https://github.com/webpack-contrib/webpack-hot-client). +Omitting this property will result in `webpack-hot-client` using its default +options. + +As of `v3.0.1` setting this to `false` will completely disable `webpack-hot-client` +and all automatic Hot Module Replacement functionality. + +## Using with koa-compress + +When using `koa-webpack` with [koa-compress](https://github.com/koajs/compress), +you may experience issues with saving files and hot module reload. Please review +[this issue](https://github.com/shellscape/koa-webpack/issues/36#issuecomment-289565573) +for more information and a workaround. + +## Server-Side-Rendering + +When `serverSideRender` is set to true in `config.dev`, `webpackStats` is accessible from `ctx.state.webpackStats`. + +```js +app.use(async (ctx, next) => { + const assetsByChunkName = ctx.state.webpackStats.toJson().assetsByChunkName; + // do something with assetsByChunkName +}) +``` + +For more details please refer to: [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware#server-side-rendering) + +## Lint and test + +```bash +npm install +npm run lint +npm test +``` + +## Contributing + +We welcome your contributions! Please have a read of [CONTRIBUTING](CONTRIBUTING.md). + +## Attribution + +This module started as a fork of [`koa-webpack-middleware`](https://github.com/leecade/koa-webpack-middleware) diff --git a/node_modules/koa-webpack/index.js b/node_modules/koa-webpack/index.js new file mode 100755 index 00000000..1acb6f01 --- /dev/null +++ b/node_modules/koa-webpack/index.js @@ -0,0 +1,95 @@ +'use strict'; + +const path = require('path'); +const Webpack = require('webpack'); +const devMiddleware = require('webpack-dev-middleware'); +const hotClient = require('webpack-hot-client'); +const root = require('app-root-path'); + +/** + * @method koaDevware + * @desc Middleware for Koa to proxy webpack-dev-middleware + **/ +function koaDevware(dev, compiler) { + /** + * @method waitMiddleware + * @desc Provides blocking for the Webpack processes to complete. + **/ + function waitMiddleware() { + return new Promise((resolve, reject) => { + dev.waitUntilValid(() => { + resolve(true); + }); + + function tapFailedHook(comp) { + comp.hooks.failed.tap('KoaWebpack', (error) => { + reject(error); + }); + } + + if (compiler.compilers) { + for (const child of compiler.compilers) { + tapFailedHook(child); + } + } else { + tapFailedHook(compiler); + } + }); + } + + return (context, next) => Promise.all([ + waitMiddleware(), + new Promise((resolve) => { + dev(context.req, { + end: (content) => { + context.body = content; // eslint-disable-line no-param-reassign + resolve(); + }, + setHeader: context.set.bind(context), + locals: context.state + }, () => resolve(next())); + }) + ]); +} + +/** + * The entry point for the Koa middleware. + **/ +module.exports = function fn(opts) { + const defaults = { dev: {}, hot: {} }; + + const options = Object.assign(defaults, opts); + + let { compiler, config } = options; + + if (!compiler) { + if (!config) { + // eslint-disable-next-line import/no-dynamic-require, global-require + config = require(path.join(root.path, 'webpack.config.js')); + } + + compiler = Webpack(config); + } + + if (!options.dev.publicPath) { + const { publicPath } = compiler.options.output; + + if (!publicPath) { + throw new Error('koa-webpack: publicPath must be set on `dev` options, or in a compiler\'s `output` configuration.'); + } + + options.dev.publicPath = publicPath; + } + + const client = options.hot ? hotClient(compiler, options.hot) : null; + const dev = devMiddleware(compiler, options.dev); + + return Object.assign(koaDevware(dev, compiler), { + dev, + client, + close(callback) { + const next = client ? () => { client.close(callback); } : callback; + dev.close(next); + } + }); +}; diff --git a/node_modules/koa-webpack/node_modules/.bin/webpack b/node_modules/koa-webpack/node_modules/.bin/webpack new file mode 120000 index 00000000..8a1900f6 --- /dev/null +++ b/node_modules/koa-webpack/node_modules/.bin/webpack @@ -0,0 +1 @@ +../../../webpack/bin/webpack.js
\ No newline at end of file diff --git a/node_modules/koa-webpack/package.json b/node_modules/koa-webpack/package.json new file mode 100644 index 00000000..a1b87d38 --- /dev/null +++ b/node_modules/koa-webpack/package.json @@ -0,0 +1,48 @@ +{ + "name": "koa-webpack", + "version": "4.0.0", + "description": "Development and Hot Reload Middleware for Koa2", + "license": "MIT", + "repository": "shellscape/koa-webpack", + "author": "Andrew Powell <andrew@shellscape.org>", + "main": "index.js", + "engines": { + "node": ">= 6.0.0" + }, + "scripts": { + "ci": "npm run lint && npm run test", + "mocha": "mocha test/test.js --exit", + "lint": "eslint index.js test/*.js", + "test": "npm run mocha" + }, + "peerDependencies": { + "webpack": "^4.0.0" + }, + "dependencies": { + "app-root-path": "^2.0.1", + "merge-options": "^1.0.0", + "webpack-dev-middleware": "^3.0.0", + "webpack-hot-client": "^3.0.0", + "webpack-log": "^1.1.1" + }, + "devDependencies": { + "@babel/cli": "^7.0.0-beta.37", + "@babel/core": "^7.0.0-beta.37", + "@babel/polyfill": "^7.0.0-beta.37", + "@babel/preset-env": "^7.0.0-beta.37", + "@babel/register": "^7.0.0-beta.37", + "deepmerge": "^2.0.1", + "eslint": "^4.1.0", + "eslint-config-webpack": "^1.2.5", + "eslint-plugin-import": "^2.8.0", + "killable": "^1.0.0", + "koa": "^2.2.0", + "koa-compose": "^4.0.0", + "loud-rejection": "^1.6.0", + "mocha": "^5.0.1", + "server-destroy": "^1.0.1", + "supertest": "^3.0.0", + "webpack": "^4.0.1", + "wtfnode": "^0.6.0" + } +} diff --git a/node_modules/koa-webpack/test/fixtures/input.js b/node_modules/koa-webpack/test/fixtures/input.js new file mode 100644 index 00000000..625c2d15 --- /dev/null +++ b/node_modules/koa-webpack/test/fixtures/input.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log('Hello world'); // eslint-disable-line diff --git a/node_modules/koa-webpack/test/results.js b/node_modules/koa-webpack/test/results.js new file mode 100644 index 00000000..563d4256 --- /dev/null +++ b/node_modules/koa-webpack/test/results.js @@ -0,0 +1,159 @@ +'use strict'; + +const assert = require('assert'); +const path = require('path'); +const killable = require('killable'); +const merge = require('merge-options'); +const Koa = require('koa'); +const compose = require('koa-compose'); +const request = require('supertest'); +const Webpack = require('webpack'); +const koaWebpack = require('../index'); + +const DEFAULT_OPTIONS = { + mode: 'development', + config: { + entry: [path.resolve(__dirname, 'fixtures', 'input.js')], + output: { + path: path.resolve(__dirname, 'fixtures'), + filename: 'output.js' + } + }, + dev: { + publicPath: '/', + logLevel: 'silent' + }, + hot: { + logLevel: 'silent' + } +}; + +function buildOptions(opts) { + const options = merge({}, DEFAULT_OPTIONS, opts); + return merge(options, { + config: null, + compiler: Webpack(options.config) + }); +} + +function defaultApp(middleware) { + return middleware; +} + +function setup(options, setupMiddleware = defaultApp) { + const app = new Koa(); + const middleware = koaWebpack(buildOptions(options)); + app.use(setupMiddleware(middleware)); + const server = app.listen(); + const req = request(server); + killable(server); + return { middleware, req, server }; +} + +describe('koa-webpack', () => { + it('should provide access to middleware and client', (done) => { + const { middleware, server, req } = setup({ dev: { lazy: false } }); + + req.get('/output.js') + .then(() => { + assert(middleware.dev); + assert(middleware.client); + + server.kill(); + middleware.close(done); + }); + }).timeout(5e3); + + it('should disable hot-client', (done) => { + const { middleware, server, req } = setup({ dev: { lazy: false }, hot: false }); + + req.get('/output.js') + .then(() => { + assert(middleware.dev); + assert.equal(middleware.client, null); + + server.kill(); + middleware.close(done); + }); + }).timeout(5e3); + + it('sends the result in watch mode', (done) => { + const { middleware, req, server } = setup({ dev: { lazy: false } }); + req.get('/output.js') + .expect(200) + .expect((response) => { + assert.ok(/Hello world/.test(response.text), "Expected result to contain 'Hello world'"); + }) + .then(() => { + server.kill(); + middleware.close(done); + }); + }).timeout(5e3); + + it('sends the result to a MultiCompiler in watch mode', (done) => { + const { middleware, req, server } = setup({ + dev: { lazy: false }, + config: [ + { + entry: [path.resolve(__dirname, 'fixtures', 'input.js')], + output: { + path: path.resolve(__dirname, 'fixtures'), + filename: 'output.js' + } + }, + { + entry: [path.resolve(__dirname, 'fixtures', 'input.js')], + output: { + path: path.resolve(__dirname, 'fixtures'), + filename: 'output2.js' + } + } + ] + }); + req.get('/output.js') + .expect(200) + .expect((response) => { + assert.ok(/Hello world/.test(response.text), "Expected result to contain 'Hello world'"); + }) + .then(() => req.get('/output2.js') + .expect(200) + .expect((response) => { + assert.ok(/Hello world/.test(response.text), "Expected result to contain 'Hello world'"); + }) + .then(() => { + server.kill(); + middleware.close(done); + })); + }).timeout(5e3); + + it('builds and sends the result in lazy mode', (done) => { + const { middleware, req, server } = setup({ dev: { lazy: true } }); + req.get('/output.js') + .expect(200) + .expect((response) => { + assert.ok(/Hello world/.test(response.text), "Expected result to contain 'Hello world'"); + }) + .then(() => { + server.kill(); + middleware.close(done); + }); + }).timeout(5e3); + + it('continues on if the file is not part of webpack', (done) => { + const mware = webpack => + compose([ + webpack, + async (ctx) => { + ctx.body = 'foo'; // eslint-disable-line + } + ]); + + const { middleware, req, server } = setup({}, mware); + req.get('/some-other-file.js') + .expect(200, 'foo') + .then(() => { + server.kill(); + middleware.close(done); + }); + }).timeout(5e3); +}); diff --git a/node_modules/koa-webpack/test/test.js b/node_modules/koa-webpack/test/test.js new file mode 100644 index 00000000..c33adf72 --- /dev/null +++ b/node_modules/koa-webpack/test/test.js @@ -0,0 +1,20 @@ +'use strict'; + +/* eslint global-require: off */ +require('loud-rejection/register'); + +if (parseInt(process.version.substring(1), 10) < 8) { + require('@babel/polyfill'); + require('@babel/register')({ + ignore: [/node_modules\/(?!koa)/], + presets: [ + ['@babel/preset-env', { + targets: { + node: '6.11' + } + }] + ] + }); +} + +require('./results'); |
