html标签中百分号表达式的含义是什么?

时间:2016-10-17 09:09:52

标签: javascript html

我发现了一些奇怪的标志< %%>在angular2-seed中,什么是< %%>用于?

https://github.com/AngularClass/angular2-webpack-starter/blob/master/src/index.html

<!DOCTYPE html>
<html lang="">
<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title><%= htmlWebpackPlugin.options.title %></title>

  <meta name="description" content="<%= htmlWebpackPlugin.options.title %>">

  <% if (webpackConfig.htmlElements.headTags) { %>
  <!-- Configured Head Tags  -->
  <%= webpackConfig.htmlElements.headTags %>
  <% } %>

  <!-- base url -->
  <base href="<%= htmlWebpackPlugin.options.metadata.baseUrl %>">


</head>

<body>

  <app>
    Loading...
  </app>

 .....

  <% if (htmlWebpackPlugin.options.metadata.isDevServer && htmlWebpackPlugin.options.metadata.HMR !== true) { %>
  <!-- Webpack Dev Server reload -->
  <script src="/webpack-dev-server.js"></script>
  <% } %>


</body>
</html>

2 个答案:

答案 0 :(得分:3)

这通常由HTTP服务器中的代码处理,并在完整页面作为对浏览器请求的响应发送之前由动态生成的字符串替换。

参见例如

答案 1 :(得分:2)

实际上它是HTML Webpack插件 https://github.com/ampedandwired/html-webpack-plugin

如果针对项目搜索HtmlWebpackPlugin,您将获得以下js,它指向模板文件,模板引擎帮助将其解码为html文件。

   /*
   * Plugin: HtmlWebpackPlugin
   * Description: Simplifies creation of HTML files to serve your webpack bundles.
   * This is especially useful for webpack bundles that include a hash in the filename
   * which changes every compilation.
   *
   * See: https://github.com/ampedandwired/html-webpack-plugin
   */
  new HtmlWebpackPlugin({
    template: 'src/index.html',
    title: METADATA.title,
    chunksSortMode: 'dependency',
    metadata: METADATA,
    inject: 'head'
  }),

我认为这是你想要弄清楚的。