Skip to content
This repository has been archived by the owner on Apr 5, 2021. It is now read-only.

Inject external file many times #45

Open
sknightq opened this issue May 14, 2019 · 5 comments
Open

Inject external file many times #45

sknightq opened this issue May 14, 2019 · 5 comments

Comments

@sknightq
Copy link

sknightq commented May 14, 2019

I have many entries and each entry need to inject an external javascript called aepmod.js (just like a CDN jquery), but I got wrong times of injection in my dist folder.
image
image

The first file gets one inject.
The second one gets two,
The third one gets three
.....
The last one gets many times (The times depend on the order of my file)!
image
Following is my webpack production config:
image
And the path in 'externals' config represents the URL of aepmod.js

@sknightq
Copy link
Author

What's more, everything will be OK if I use my old node_modules.
But I found the versions of html-webpack-externals-plugin in two node_modules are same (v3.8.0)
The old node_modules is created under node-v8.11.0
The new one is created under node-v8.16.0

@sknightq
Copy link
Author

I used html-webpack-tags-plugin that is depended by html-webpack-externals-plugin to resolve my problem.
This plugin should be upgraded.

      new HtmlWebpackTagsPlugin({
        append: false,
        publicPath: false,
        tags: [
          baseConfig.build.corsDomain +
            ':' +
            baseConfig.build.corsMainPort +
            baseConfig.build.externalJs
        ]
      })

@Trendymen
Copy link

I have the same problem.

@sknightq
Copy link
Author

sknightq commented Dec 25, 2019

I have the same problem.

@Trendymen You can use html-webpack-tags-html to replace of html-webpack-externals-plugin.
This is example.

@IMakiMaki
Copy link

I have the same problem.

@Trendymen You can use html-webpack-tags-html to replace of html-webpack-externals-plugin.
This is example.

There is still one way to continue to use this plugin, if you want.(I try many times to make it before I see this issue, too sad.)

Create one option array of this plugins in the file which you create multiple entries, each of option specify the html you want to inject.

// util.js
htmlWebpackExternalsPlugins.push(
   new htmlWebpackExternalsPlugin({
       externals: externalsConfig,
       hash: true,
       files: [`${pageName}.html`],
    })
);
export htmlWebpackExternalsPlugins;
// webpack.prod.js
const { htmlWebpackExternalsPlugins } = require('./utils.js')
module.exports = {
    plugins: [
        ....htmlWebpackExternalsPlugins
    ]
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants