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

5
我在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个回答

5

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'
  }),

我想这就是你试图弄清楚的内容。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接