项目作者: CharlesMoone

项目描述 :
webcomponent + koa2
高级语言: JavaScript
项目地址: git://github.com/CharlesMoone/website.git
创建时间: 2019-09-16T01:56:14Z
项目社区:https://github.com/CharlesMoone/website

开源协议:

下载


webcomponent + koa2

Start

  1. npm install
  2. mongod —dbpath /path/to/your/mongodb
  3. npm run watch
  4. npm run dev
  5. add file server/utils/keys.mjs
  1. export default 'charlesmoone&weDoctor';

Design

use webpack to handle ‘.mhtml’ file, the loader is ‘mhtmlLoader/index.js’

webcomponent need be used in <template ></template>

  1. // mhtmlLoader/index.js
  2. module.exports = function(source) {
  3. return `
  4. const template = document.createElement('template');
  5. template.innerHTML = \`${source}\`;
  6. export default template;
  7. `;
  8. };

conver the html to string

use in html like:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  7. <title>Start your travel</title>
  8. <link rel="stylesheet" href="/css/reset.css" />
  9. <link rel="stylesheet" href="/css/home.css" />
  10. <script type="module" src="/js/webcomponent/cm-header.js"></script>
  11. </head>
  12. <body>
  13. <cm-header></cm-header>
  14. </body>
  15. </html>

Server

  1. middleware # middleware for router
  2. routers # the router
  3. utils # common tools
  4. controllers # the controller
  5. models # the model to connect mongodb
  6. index.mjs # entry