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

max*_*der 3 html javascript

我在 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>
Run Code Online (Sandbox Code Playgroud)

Gün*_*uer 5

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

见例如


Ela*_*ine 3

实际上它是 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'
  }),
Run Code Online (Sandbox Code Playgroud)

我想这就是你想要弄清楚的。