new-webpack: serve static files (#567)

Summary:
This commit makes the Webpack dev server fully functional under the new
config, by serving the static SourceCred directory via a piece of
injected middleware.

Test Plan:
Run

```
NODE_ENV=development node ./node_modules/.bin/webpack-dev-server \
    --config config/makeWebpackConfig.js
```

and navigate to the cred explorer. Note that the repository registry is
fetched, and the whole cred explorer works.

wchargin-branch: webpack-statics
This commit is contained in:
William Chargin 2018-07-30 17:29:34 -07:00 committed by GitHub
parent 37eddcaf27
commit 1d48bf9390
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,7 @@
// @flow
const express = require("express");
/*:: import type {$Application as ExpressApp} from "express"; */
const os = require("os");
const path = require("path");
const webpack = require("webpack");
const ManifestPlugin = require("webpack-manifest-plugin");
@ -38,6 +41,16 @@ function makeConfig(mode /*: "production" | "development" */) {
},
devServer: {
inline: false,
before: (app /*: ExpressApp */) => {
// TODO(@wchargin): De-duplicate this code.
app.use(
"/api/v1/data",
express.static(
process.env.SOURCECRED_DIRECTORY ||
path.join(os.tmpdir(), "sourcecred")
)
);
},
},
output: {
// The build folder.