Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incompatibility with html-webpack-inline-source-plugin #44

Open
id0Sch opened this issue May 7, 2018 · 12 comments
Open

incompatibility with html-webpack-inline-source-plugin #44

id0Sch opened this issue May 7, 2018 · 12 comments

Comments

@id0Sch
Copy link

id0Sch commented May 7, 2018

Hi,
I'm trying to add dynamic cdn support for my repo but I encounter this error:

  ERROR in Cannot read property 'map' of undefined
    ERROR in   TypeError: Cannot read property 'options' of undefined
      - index.js:23
        [templates_generator]/[html-webpack-inline-source-plugin]/index.js:23:36
      - new Promise
      - Hook.js:35 AsyncSeriesWaterfallHook.lazyCompileHook [as _promise]
        [templates_generator]/[tapable]/lib/Hook.js:35:21
      - index.js:673
        [templates_generator]/[html-webpack-plugin]/index.js:673:47
      - index.js:187 Promise.resolve.then.then.then.then.then.then.then.result
        [templates_generator]/[html-webpack-plugin]/index.js:187:18
      - next_tick.js:188 process._tickCallback
        internal/process/next_tick.js:188:7

Everything was working fine before I added dynamic-cdn and this is my plugins section (ignore the dynamic entry suport)
I saw in the code that this plugin applies the HTMLwbepack plugin and I suspect that this causes the inline-source-plugin to not work.

new HtmlWebpackPlugin({
        template: entry.template,
        filename: `${entry.chunkName}.html`,
        inlineSource: entry.splitBundle ? `(runtime.*.js$|DL.*.js$|${entry.chunkName}.*.css$)` : '.(js|css)$',
        inject: 'head',
        chunksSortMode: entry.splitBundle ? function (a, b) {
          let orders = ['runtime', 'DL', 'vendor', entry.chunkName]
          if (orders.indexOf(a.names[0]) > orders.indexOf(b.names[0])) {
            return 1
          } else if (orders.indexOf(a.names[0]) < orders.indexOf(b.names[0])) {
            return -1
          } else {
            return 0
          }
        } : () => 0
      }),
      new DynamicCdnWebpackPlugin({
        only: ['react', 'react-dom']
      }),

versions

"dynamic-cdn-webpack-plugin": "^4.0.0-rc.1",
"html-webpack-inline-source-plugin": "^0.0.10",
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.5.0",

It would be great to be able to use both plugins,
Thanks for the hard workd on this project!

@aulisius
Copy link
Collaborator

aulisius commented May 7, 2018

Which version of the plugins are you using? Note that dynamic-cdn-webpack >= 4 only works on webpack >=4

@id0Sch
Copy link
Author

id0Sch commented May 7, 2018

Of course :)

"dynamic-cdn-webpack-plugin": "^4.0.0-rc.1",
"html-webpack-inline-source-plugin": "^0.0.10",
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.5.0",

@id0Sch
Copy link
Author

id0Sch commented May 10, 2018

@aulisius do you have any idea what causes it? because for now I've hardcoded the react min bundle in my HTML and it's such a bad practice :\

@mastilver
Copy link
Owner

@id0Sch Can you confirm me that everything is working fine, without dynamic-cdn-webpack-plugin

I'm asking because html-webpack-inline-source-plugin doesn't have test running webpack@4 and html-webpack-plugin@3 so it might be a bug on there side

@id0Sch
Copy link
Author

id0Sch commented May 10, 2018 via email

@id0Sch
Copy link
Author

id0Sch commented May 13, 2018

I can't see any issue in inline-source that could cause this issue.

@aulisius
Copy link
Collaborator

Bit busy with vacation. Will try to get to this tmrw. I think it might be something to do with ordering of plugins and in what order they access the HtmlWebpackPlugin event hooks.

@aulisius
Copy link
Collaborator

Finally got around to creating a repro https://github.com/aulisius/dynamic-cdn-issue-44-repro/blob/master/webpack.config.js . Really sorry for the delay @id0Sch . Will get working soon.

@id0Sch
Copy link
Author

id0Sch commented Jun 3, 2018

@aulisius It's fine :)
Let me know if you need anything else 👍
Thanks again!

@mastilver
Copy link
Owner

mastilver commented Jul 9, 2018

@id0Sch Sorry for the delay, I don't think there is a real solution here as if you try to in-line the JS, you are loosing the benefit of this plugin

https://github.com/DustinJackson/html-webpack-inline-source-plugin#basic-usage has a inlineSource options that should be used to not include url starting by https://unpkg.com/#/


I wonder if we can make the error more explicit
Maybe we should set source to throw when called?

@njzjz
Copy link

njzjz commented Dec 27, 2019

Any progress or advice to solve this issue? I met the same problem.

@cheungpat
Copy link

I have the same issue. I want big dependencies to be fetched from CDN while keeping my code inline.

The key is to modify the inlineSource to only include sources that are local.

Here is how I fixed it:

      new HtmlWebpackPlugin({
        inlineSource: '^[^(//)]+\.(js|css)$' // exclude source with `//`
      }),
      new DynamicCdnWebpackPlugin(),
      new HtmlWebpackInlineSourcePlugin(),

@njzjz I hope this is helpful.

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

No branches or pull requests

5 participants