简体   繁体   中英

How can I include a script tag in my template html for webpack with html-webpack-plugin

I am trying to include a script tag in the head of my html template but I am receiving an error saying "can't resolve../vendorlib/vendor.js". Vendor.js will not be an output of webpack but there will be other libraries to where I'm deploying this application and I want to have access to those. html-webpack-plugin I think is trying to parse this part but can't find the resource. Is there a way to exclude script tags from being checked?

I was able to accomplish this using gulp. I used index-* since my output html is hashed.

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();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM