question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

incompatibility with html-webpack-inline-source-plugin

See original GitHub issue

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!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
cheungpatcommented, Jan 8, 2020

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.

2reactions
mastilvercommented, 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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inline JavaScript and CSS with webpack - Stack Overflow
Use InlineChunkHtmlPlugin from react-dev-utils const HtmlWebpackPlugin = require('html-webpack-plugin'); const InlineChunkHtmlPlugin ...
Read more >
html-webpack-inline-source-plugin - npm
Embed javascript and css source inline when using the webpack dev server or middleware. Latest version: 0.0.10, last published: 5 years ago.
Read more >
vuepress-html-webpack-plugin | Yarn - Package Manager
This is published as vuepress-html-webpack-plugin to be used in VuePress. ... up requiring the internal modules from the incompatible version of webpack.
Read more >
Html-webpack-plugin NPM
source () (see the inline template example). The template can also be directly inlined directly into the options object. ⚠️ templateContent does not...
Read more >
sass-loader - webpack - JS.ORG
Using ~ is deprecated and can be removed from your code (we recommend it), but we still support it for historical reasons. Why...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found