From 551cf63d2e0feb03004da1fa3c7e2b7cbbc15ddf Mon Sep 17 00:00:00 2001 From: Coding Girl Date: Tue, 25 Jun 2019 05:28:29 +0800 Subject: [PATCH] Update installing.md (#1349) Add lasso configuration description for "Initializing server-rendered components", let it clearly to read and more easy in practice. --- docs/installing.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/installing.md b/docs/installing.md index 4d85ab21b..e32e87041 100644 --- a/docs/installing.md +++ b/docs/installing.md @@ -178,6 +178,25 @@ First install `lasso` and `lasso-marko`: npm install --save lasso lasso-marko @lasso/marko-taglib ``` +Next, register and config the lasso: + +_server.js_ + +``` +var isProduction = process.env.NODE_ENV === 'production'; + +// Configure lasso to control how JS/CSS/etc. is delivered to the browser +require('lasso').configure({ + plugins: [ + 'lasso-marko' // Allow Marko templates to be compiled and transported to the browser + ], + outputDir: __dirname + '/static', // Place all generated JS/CSS/etc. files into the "static" dir + bundlingEnabled: isProduction, // Only enable bundling in production + minify: isProduction, // Only minify JS and CSS code in production + fingerprintsEnabled: isProduction, // Only add fingerprints to URLs in production +}); +``` + Next, in your page or layout view, add the `lasso-head` and `lasso-body` tags: _layout.marko_ @@ -198,8 +217,23 @@ _layout.marko_ Finally, configure your server to serve the static files that `lasso` generates: +If you're using `express`, just do: + _server.js_ ```js app.use(require("lasso/middleware").serveStatic()); ``` + +And if `koa`, do: + +_server.js_ + +``` +const mount = require('koa-mount'); +const serve = require('koa-static'); + +app.use(mount('/static', serve(__dirname + '/static'))); +``` + +For the full application code for the Koa and assets bundling, please see the sample: [Marko + Koa](https://github.com/marko-js-samples/marko-koa).