-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb42d71
commit f898f30
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# @livingdocs/fastify-webpack | ||
|
||
More details will follow | ||
|
||
``` | ||
npm install fastify @livingdocs/fastify-webpack | ||
npm install --save-dev fastify-webpack-hmr | ||
``` | ||
|
||
```js | ||
const fastify = require('fastify') | ||
const fastifyWebpack = require('@livingdocs/fastify-webpack') | ||
|
||
const watch = process.argv.slice(2).includes('watch') | ||
const optimized = process.argv.slice(2).includes('optimize') | ||
|
||
fastify.register(fastifyWebpack, { | ||
watch, | ||
// Force the expiration when `watch` isn't true | ||
maxAge: '1y', | ||
// we can define the cdnurl | ||
cdnUrl: 'https://somecdn.yourproject.com', | ||
// optional, by default it uses webpack.config.js | ||
webpackConfig: require('./custom-webpack-config') | ||
}) | ||
|
||
fastify.get('/', fastify.webpackHtml({ | ||
body: '<h1>Hello</h1>' | ||
})) | ||
``` | ||
|
||
|
||
```js | ||
const fastifyWebpack = require('@livingdocs/fastify-webpack') | ||
module.exports = { | ||
context: __dirname, | ||
mode: optimized ? 'production' : 'development', | ||
stats: false, | ||
entry: { | ||
index: './src/index.js' | ||
}, | ||
output: { | ||
// make sure that there's no `/` in the front, so all the assets | ||
// are referenced using relative urls. | ||
// This allows us to host the files anywhere on any url, even subdirectories | ||
publicPath: 'assets/', | ||
filename: optimized ? '[name].[contenthash].js' : '[name].[hash].js', | ||
chunkFilename: optimized ? '[name].[contenthash].js' : '[name].[hash].js' | ||
}, | ||
plugins: [new fastifyWebpack.AssetManifestPlugin()] | ||
} | ||
``` |