Skip to content

Conversation

@Joy9001
Copy link

@Joy9001 Joy9001 commented Jul 10, 2024

What

  • I've modified the "EjsWebpackPlugin.prototype.apply" function to make it compatible with webpack5.
  • I also fixed the tags in the "makeTags" function.
  • I finally added an "index.d.ts" file to fix the import warning.

Why

  • The "compiler.plugin" method no longer works in webpack5.
  • There aren't any double quotes and there are backward slashes () instead of forward slashes (/) in the tags. Also, it was adding the "js" files in the link stylesheet tag.
  • When importing the plugin (import ejsPlugin from 'ejs-webpack-plugin') it gives a warning "Could not find a declaration file for module 'ejs-webpack-plugin'".

How

  • I replaced the compiler.plugin('emit', function (compilation, callback) { ... } method with compiler.hooks.emit.tapAsync('EjsWebpackPlugin', function (compilation, callback) { ... }.
  • I used the path.posix.normalize to convert the backward slashes to forward slashes. I replaced the new RegExp(file).test(path.normalize(i)) with /\.css/.test(path.normalize(i)) to prevent it from adding "js" files in a link tag. Also, I added the "defer" to load the js after the document is parsed.
  • I added declare module 'ejs-webpack-plugin'; in index.d.ts to resolve the import warning.

Screenshots

  • issue-1
    issue-1
  • issue-2
    issue-2
  • issue-3
    issue-3

Request

Your plugin is just awesome. I had the issue with ejs combining with webpack for months and at last, your plugin has solved the issue. Please look into the PR and let me know if it's worth merging. And I would request you to update the npm distribution as it may help other developers. Thank you 😄.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant