【问题标题】:How can I include a script tag in my template html for webpack with html-webpack-plugin如何使用 html-webpack-plugin 在我的 webpack 模板 html 中包含脚本标签
【发布时间】:2021-05-25 18:09:26
【问题描述】:

我试图在我的 html 模板的头部包含一个脚本标记,但我收到一条错误消息,提示“无法解析 ../vendorlib/vendor.js”。 Vendor.js 不会是 webpack 的输出,但会有其他库到我部署此应用程序的位置,我希望能够访问这些库。 html-webpack-plugin 我认为正在尝试解析这部分但找不到资源。有没有办法排除脚本标签被检查?

【问题讨论】:

    标签: javascript node.js webpack html-webpack-plugin


    【解决方案1】:

    我能够使用 gulp 完成此任务。我使用 index-* 因为我的输出 html 是散列的。

    const gulp = require("gulp");
    const zip = require("gulp-zip");
    const inject = require("gulp-inject-string");
    
    gulp.task("insert", function (done) {
      gulp
        .src("./dist/index-*.html")
        .pipe(
          inject.before(
            "<title>",
            '<script defer="defer" src="../vendorlib/vendor.js"></script>'
          )
        )
        .pipe(gulp.dest("./dist/"));
      console.log("This is insert task!");
      done();
    });
    
    

    【讨论】:

      猜你喜欢
      • 2016-05-21
      • 1970-01-01
      • 2016-12-28
      • 2016-11-26
      • 2018-03-19
      • 1970-01-01
      • 1970-01-01
      • 2017-06-05
      • 2023-03-19
      相关资源
      最近更新 更多