Code Monkey home page Code Monkey logo

webpack-require-from's Introduction

npm version npm CircleCI

webpack-require-from

Control the dynamic imports path / URL at runtime

Table of contents

Why changing dynamic imports path at runtime?

Webpack allows to split and load code atomatically using require.ensure or dynamic import import(). Modules are fetched "on-demand" when your main bundle is running in browser.

Webpack loads the modules (chunks) from a static URL, which is determined by config.output.publicPath of webpack configuration.

Sometimes you need to control this modules (chunks) URL at runtime, for example:

  • Chunks are hosted at a CDN
  • Different environments use different URLs for loading assets (production, staging, qa)
  • Your index file is served from a different location / port
  • You need to dynamically load pre-compiled files from a different location
  • You need to load 3rd part web worker from a CDN

How to use

// webpack.config.js
const WebpackRequireFrom = require("webpack-require-from");
const webpackRequireFromConfig = (module.exports = {
  output: {
    publicPath: "/webpack/"
  },
  plugins: [
    new WebpackRequireFrom({
      // see configuration options below
    })
  ]
});

Configuration

If no options provided, the plugin will use the default config.output.publicPath. Check out the "example" directory.

path

Set path for dynamically loading modules. The value you provide will replace config.output.publicPath when dynamically importing chunks.

For example, if default URL is https://localhost, chunk name is 0.js and options object is {path: "customPath/" }, the chunk will be fetched from https://localhost/customPath/0.js

NOTE path, methodName and variableName are mutualy exclusive and cannot be used together

variableName

variableName is the globaly defined variable that will be evaluated at runtime, variableName is the name of a variable with string value that represents a path / URL that will be used for dynamically importing of chunks.

For example, if default URL is https://localhost, chunk name is 0.js and options object is {variableName: "chunkURL" }, while window.chunkURL is defined to be:

window.chunkURL = "https://app.cdn.com/buildXXX/";

the chunk will be fetched from https://app.cdn.com/buildXXX/0.js

methodName

Name of the globaly defined method that will be invoked at runtime, the method should return a path / URL that will be used for dynamically importing of chunks.

For example, if default URL is https://localhost, chunk name is 0.js and options object is {methodName: "getChunkURL" }, while window.getChunkURL is defined to be:

window.getChunkURL = function() {
  if (true) {
    // use any condition to choose the URL
    return "https://app.cdn.com/buildXXX/";
  }
};

the chunk will be fetched from https://app.cdn.com/buildXXX/0.js

If used together with replaceSrcMethodName, chunks URL will be first modified by window[methodName] and then, the modified values are passed as an argument to window[replaceSrcMethodName] function.

NOTE path, methodName and variableName are mutualy exclusive and cannot be used together

NOTE that the method should be defined in a global namespace and should be defined before require.ensure or import() is invoked. See examples below

replaceSrcMethodName

Name of the globaly defined method that will be invoked at runtime; the method receives the full URL of the dynamically required chunk as its argument and should return a string with the new URL.

For example, if default URL is https://localhost, chunk names are 0.js and common.js, options object is {replaceSrcMethodName: "replaceSrc" }, while window.replaceSrc is defined to be:

window.replaceSrc = function(originalSrc) {
  if (originalSrc.match(/common/)) {
    // rename specific chunk
    return originalSrc.replace(/common/, "static");
  }
  return originalSrc;
};

the chunks will be fetched from https://localhost/0.js and https://localhost/static.js

If used together with methodName or variableName, chunks URL will be first modified by window[methodName] or will be modified to window[variableName] and then, the modified values are passed as an argument to window[replaceSrcMethodName] function.

NOTE that the method should be defined in a global namespace and should be defined before require.ensure or import() is invoked.

suppressErrors

default: false. The plugin will invoke console.error when the method name you defined in replaceSrcMethodName, methodName or variableName cannot be detected. Turning this option on will suppress the error messages.

Global methods and variables

When your JS code is executed in browser, the variable/methods whose names you mention as variableName, methodName or replaceSrcMethodName value, should be set before the first call to require.ensure() or import() is executed.

The return value of the methods will be used to build the URL for fetching resources.

For example, let's define veryFirst method to be globally available before you main bundle is being executed.

Add the method definition at the very first line of you bundle:

const window.veryFirst = function () {
 console.log("I am very first!");
}

You can use a separate file and use webpack's entry point list:

// filename: veryFirst.js
const window.veryFirst = function () {
 console.log("I am very first!");
}

// file webpack.config.js
module.exports = {
  entry: {
    ['./veryFirst.js', './index.js']
  }
}

Another approach is to define veryFirst as part of index.html when building it on your server:

// filename: server/app.js
app.get("/", (req, res) =>
  res.render("views/index", {
    cdnPath: "https://qa.cdn.com/|https://prod.cdn.com/"
  })
);
<!-- filename: views/index.ejs -->
<html>
<script>
  const baseCDN = "<%= cdnPath %>";
  window.veryFirst = function () {
      console.log(`${baseCDN}/js/`);
  }
</script>
...
</html>

Web Workers

TL;DR

Use replaceSrcMethodName to provide a method for modifying web-worker loading path. The method must be globally available and defined before import() calls within your web-worker. From example directory:

/* webpack.config.js */
  // ...
  module: {
    rules: [
      {
        test: /worker\.js$/,
        use: {
          loader: `worker-loader`
        }
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin(),
    new RequireFrom({
      replaceSrcMethodName: "getSrc"
    })
  ]
  // ...


/* worker.js */
require("./globals.js");

import("./worker-module.js").then(workerModule => {
  workerModule.default();
  console.log("loaded workerModule");
});

Details

The plugin allows to change the loading path of web-workers.

Do to so, use the worker-loader loader. The loader uses importScripts to dynamically load modules from within your web-worker and support cross-domain web workers. More specifically it:

  1. Creates a new webpack entry that only contains new Worker(workerURL), while workerURL is your main webworker module
  2. Enhances your webworker main module with webpack runtime utilities
  3. Uses importScripts to dynamically load new modules within webworker context (thus avoiding cross-domain limitations)

The plugin monkey-patches importScripts and invokes the method you've defined within replaceSrcMethodName configuration option. The method you've provided will be invoked just before calling importScripts with the required module path as the single argument.

Check out the working example of using the plugin with web-workers at web2fs-notepad by @sushain97.

Troubleshooting

${methodName} is not a function or not available at runtime.

  • Make sure your method name in webpack.config.js matches the method name you define on global window object.

  • Make sure the method is defined before the very first invocation of either require.ensure() or import()

Specify either "methodName" or "path", not together.

  • path and methodName are mutualy exclusive and cannot be used together, use either of them

'${methodName}' does not return string.

  • when using replaceSrcMethodName options the result of invoking window[replaceSrcMethodName] is validated - it should be defined and be a string

  • make sure you return a string value from window[replaceSrcMethodName]

Don't hesitate to open issues.

Tests

yarn test

webpack-require-from's People

Contributors

agoldis avatar andreszorro avatar dependabot[bot] avatar lucalooz avatar ywmail avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

webpack-require-from's Issues

Allow paths replacement for webpack 5

Webpack 5 has a simplified chunks loading mechanism via [__webpack_require__.l] (https://github.com/webpack/webpack/blob/4837c3ddb9da8e676c73d97460e19689dd9d4691/lib/RuntimeGlobals.js#L169)

monkey-patching this function would allow to create an override method like replaceSrcMethodName that accepts the original URL (and possibly more params).

The patch should via a different main template hook, because local-variables comes before __webpack_require__.l definition https://github.com/webpack/webpack/blob/4837c3ddb9da8e676c73d97460e19689dd9d4691/lib/MainTemplate.js#L241

Pass chunkName to method

Do you have an idea how the chunkName could be passed down to the method specified via methodName?
I forked your plugin and tried some things, but the problem is, that the name is undefined for a chunk when compilationHook is called, and chunk information for a certain chunk are only present in the next iteration.

[webpack 5] Uncaught ReferenceError: __webpack_require__ is not defined

I get Uncaught ReferenceError: __webpack_require__ is not defined in runtime for a bundle emitted by Webpack 5. The specifics of this bundle is that it doesn't import in any way other modules and it seems Webpack 5 won't inject its bootstrap code in such bundles thus the runtime exception when plugin tries to extend webpack_require

Bump tapable to ^1 + ^2

Hi!

Great job on the plugin, we at @Platform-OS use it for over 3 years and its been a real life saver.

Recently im struggling with keeping my dependencies a lot because it seems like some webpack plugins are requiring tapable ^2 and webpack-require-from is requiring ^1, so there is a conflict (see log at the end).

Would it be possible to bump version of tapable to ^2? Or if there are some breaking changes and you dont have time, will you accept PR if i learn how to do it?

Best, Pawel

npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: [email protected]
npm ERR! node_modules/tapable
npm ERR!   dev tapable@"^2.2.0" from the root project
npm ERR!   tapable@"^2.2.0" from [email protected]
npm ERR!   node_modules/enhanced-resolve
npm ERR!     enhanced-resolve@"^5.8.0" from [email protected]
npm ERR!     node_modules/webpack
npm ERR!       dev webpack@"^5.39.1" from the root project
npm ERR!       7 more (@webpack-cli/configtest, css-loader, esbuild-loader, ...)
npm ERR!   2 more (esbuild-loader, webpack)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer tapable@"^1.0.0" from [email protected]
npm ERR! node_modules/webpack-require-from
npm ERR!   dev webpack-require-from@"^1.8.5" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/pavel/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/pavel/.npm/_logs/2021-06-21T09_44_41_057Z-debug.log

expand hooks to css chunk links

Hey great plugin!
Is it possible to add the functionality of rewriting css links too?
Because currently iam using the replaceSrcPath hook to rewrite my js chunk urls but the method is not triggered by css chunks.
Or have I miss-configured something?

Thank you :)

Hello,

Ive been using webpack-require-from for at least 2 years, never had any issues, everything works as expected, so i just wanted to say thank you.

It is a live saver for so long for me and other people after they learn it exist, its truly a gem.


Nevermind the title - i double checked my work and this made me appreciate the quality of this piece of software even more :)

Does not work in webpack 5

Hi, I am using webpack-require-from to update the react bundle chunks dynamically, and it works perfectly fine with webpack 4, but does not work with webpack 5. I am using 1.8.2 version and bumped it up to 1.8.6 but still replaceSrcMethodName does not seems to be working. I do not see any errors.

Is this package stable with webpack 5 and is there any working example of documentation updates for this?

Thanks

Modifying URL in web worker chunk

I'm running to issues with an inline web worker with a dynamic import not being intercepted by this library. Since inline web workers are blobs and therefore need an absolute URL to successfully import scripts, I'm attempting to use this library to fix-up the URL.

e.g.

const md = await import(/* webpackChunkName: "markdown-it" */ 'markdown-it');

inside a web worker becomes something like

const md = await __webpack_require__.e(/* import() | markdown-it */ 2).then(__webpack_require__.t.bind(null, 264, 7));

which calls into

r.e = function(e) {
        var n = [];
        return n.push(Promise.resolve().then(function() {
            t[e] || importScripts(e + ".ee0bc93119ec2d63cc28.worker.js")
        })),
        Promise.all(n)
    }

Unfortunately, this isn't prepending the path it should be per the config below since it never actually results in the code below being called.

Object.defineProperty(r, "p", {
        get: function() {
            return "http://localhost:8080/"
        }
    }),
new WebpackRequireFrom({
      path: 'http://localhost:8080/',
      suppressErrors: true,
    }),

(For now, I've used a hardcoded path to see if I could get it minimally working. In practice, it would be a variable that is set similar to the advice in https://stackoverflow.com/a/22582695/1266600.)

Am I misunderstanding how something works or perhaps the intent of this library?

Feature Request: Pass the defaultPublicPath as an argument to the 'methodName' function

PR for the same: #112

Sometimes it's required to modify the publicPath while taking the defaultPublicPath as a parameter

Usecase: Multiple webpack builds on same page: and defaultPublicPath for each is something like: //mydomain.com/static/<APP_NAME>/ now I need to change it to //myOtherDomain.com/static/<APP_NAME>/

therefore, if I use the plugin like so:

new WebpackRequireFrom({methodName: 'get_public_path'})

and have get_public_path defined like so:

window.get_public_path = defaultPublicPath => defaultPublicPath.replace('myDomain', 'myOtherDomain')

I would be able to achieve it for all apps

Tests missing

Hi
Can you please provide testing for this cool plugin?

QUESTION: avoiding the error - MyFunctionName is not a function or not available at runtime

I am using this for a vuejs app that will be used within WordPress. I am providing a methodName to the configuration. I see the function called when loaded within WordPress during local development, however when I go to build the vuejs app the window.MyFunctionName does not exist because it is added from the js file that is loaded in WordPress via wp_enqueue_script Is there a way to tell the configuration not to do the methodName check during the build?

Extra request made to original url in IE/Edge

In IE/Edge, download starts when script.src is set. In webpack_require.e, the src is first set to the original url, then later overwritten by webpackRequireFrom using replaceSrcMethodName. This causes an unnecessary GET request sent to the original URL before we request the URL that we actually want. Can we move the replaceSrc code to where the src is set the first time?
image

any solution for css、image ?

really great idea to rewrite webpack_require.p to make publicPath can be dymatic in run time, but what about css、image files? is there any idea?

chunks injected by webpack-html-plugin still using the static public path

webpack.config.js

config.plugin('dynamicPublicPath').use(WebpackRequireFrom, [{ methodName: 'getExternalPublicPath' }]);

src/index.html

<script>
            window.getExternalPublicPath = function() {
                return (
                    /acpoint=local/.test(location.search) ? '//' + location.hostname : '//demo.publicpath.com'
                );
            };
        </script>

dist/index.html

<noscript
            ><strong
                >We're sorry but doesn't work properly without JavaScript enabled. Please enable it to continue.</strong
            ></noscript
        >
        <div id="app"><p style="color:#fff;">fcp</p></div>
        <script
            type="text/javascript"
            src="//demo.publicpath.com/js/chunk-vendors.b0ed90a9.js"
            crossorigin="anonymous"
        ></script>
        <script
            type="text/javascript"
            src="//demo.publicpath.com/js/index.f38b7301.js"
            crossorigin="anonymous"
        ></script>
        <script
            type="text/javascript"
            src="//demo.publicpath.com/js/vue-common-vendor.2e48dc40.js"
            crossorigin="anonymous"
        ></script>

any ideas to replace the public path of injected chunks at runtime?

Seems like Require-from does not work with "webpackHotMiddleware"

Hi there! Nice plugin, thank's a lot!

But it seems like webpack-hot-middlware ignores require-from plugin code. That's what I see in the generated file:

 	function hotDownloadManifest(requestTimeout) { // eslint-disable-line no-unused-vars
 		requestTimeout = requestTimeout || 10000;
 		return new Promise(function(resolve, reject) {
 			if(typeof XMLHttpRequest === "undefined")
 				return reject(new Error("No browser support"));
 			try {
 				var request = new XMLHttpRequest();
 				var requestPath = __webpack_require__.p + "" + hotCurrentHash + ".hot-update.json";
 				request.open("GET", requestPath, true);
 				request.timeout = requestTimeout;
 				request.send(null);
 			} catch(err) {
 				return reject(err);
 			}

So, there is not redefinition of src property, only the original "webpack_require.p".

Errors with ExtractTextPlugin and MiniCssExtractPlugin

Hello,

We have 2 projects, the first one is using webpack 3 with ExtractTextPlugin and the second is using webpack 4 with MiniCssExtractPlugin.

In both of these projects, we have a lot of errors like this one :

Error: WebpackRequireFrom: 'getChunkURL' is not a function or not available at runtime. See https://github.com/agoldis/webpack-require-from#troubleshooting
    at Function.get [as p] (H:\project\node_modules\css-loader\index.js!H:\project\node_modules\less-loader\dist\cjs.js??ref--10-2!H:\project\no
de_modules\dep\example.less:67:21)

Hopefully, everything is working but the log is now quite annoying to read...
It seems that the webpack-require-from plugin is going through our CSS chunks. Is it possible to ignore these chunks ? If not, can you consider the possibility to add an option to filter chunks ?

Thanks!

Deprecation Warnings with Webpack 5

Using webpack-require-from with Webpack 5 produces following deprecation warnings:

(node:16004) [DEP_WEBPACK_MAIN_TEMPLATE_GET_PUBLIC_PATH] DeprecationWarning: MainTemplate.getPublicPath is deprecated (use Compilation.getAssetPath(compilation.outputOptions.publicPath, options) instead)
    at C:\Users\X\Y\node_modules\webpack-require-from\src\plugin.js:110:46
 (node:16004) [DEP_WEBPACK_MAIN_TEMPLATE_REQUIRE_FN] DeprecationWarning: MainTemplate.requireFn is deprecated (use "__webpack_require__")
  at C:\Users\X\Y\node_modules\webpack-require-from\src\plugin.js:134:49

Error when both `replaceSrcMethodName` and `methodName` are present

yarn run v1.5.1
$ npm run clean && webpack --mode production

> [email protected] clean /Users/brijesh/projects/proj
> rm -rf dist && rm -rf lib

/Users/brijesh/projects/proj/node_modules/webpack-require-from/src/helpers.js:23
  return tapable.hooks[newHookName].tap.bind(
                                    ^

TypeError: Cannot read property 'tap' of undefined

Works fine when only methodName is present.

Plugin version - 1.2.3, webpack - 4

Webpack 4 support?

Am i the only one having errors on webpack 4 even though on 3.11 its working fine?

Im getting Error: __cdnUrl is not a function or not avialable at runtime

I was using the plugin to get cdnUrl when application was running in the browser to load chunks from the correct environment - every env. has its own cdn.

Now im getting this error which is kind of weird.

Cheers

[Help wanted]Can not apply the `path` options.

  • The chunk can not get from the correct path after set the path option, Please help me to check it
    webpack.base.babel.js file
/**
 * COMMON WEBPACK CONFIGURATION
 */
#
const path = require('path');
const webpack = require('webpack');
const Dotenv = require('dotenv-webpack');
const CopyPlugin = require('copy-webpack-plugin');
const WebpackRequireFrom = require('webpack-require-from');

const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const { version } = require(path.resolve(process.cwd(), 'package.json'));

module.exports = options => ({
  mode: options.mode,
  entry: options.entry,
  output: {
    // Compile into js/build.js
    path: path.resolve(process.cwd(), 'build'),
    publicPath: '/webpack/',
    // Merge with env dependent settings
    ...options.output,
  },
  optimization: options.optimization,
  module: {
    rules: [
      {
        test: /\.jsx?$/, // Transform all .js and .jsx files required somewhere with Babel
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: options.babelQuery,
        },
      },
      {
        test: /\.ts(x?)$/, // Transform typescript files with ts-loader
        exclude: /node_modules/,
        use: options.tsLoaders,
      },
      {
        // Preprocess our own .css files
        // This is the place to add your own loaders (e.g. sass/less etc.)
        // for a list of loaders, see https://webpack.js.org/loaders/#styling
        test: /\.css$/,
        exclude: /node_modules/,
        use: ['style-loader', 'css-loader'],
      },
      {
        // Preprocess 3rd party .css files located in node_modules
        test: /\.css$/,
        include: /node_modules/,
        use: ['style-loader', 'css-loader'],
      },
      {
        test: /\.(eot|otf|ttf|woff|woff2)$/,
        use: 'file-loader',
      },
      {
        test: /\.svg$/,
        use: [
          {
            loader: 'svg-url-loader',
            options: {
              // Inline files smaller than 10 kB
              limit: 10 * 1024,
              noquotes: true,
            },
          },
        ],
      },
      {
        test: /\.(jpg|png|gif)$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              // Inline files smaller than 10 kB
              limit: 10 * 1024,
            },
          },
          {
            loader: 'image-webpack-loader',
            options: {
              mozjpeg: {
                enabled: false,
                // NOTE: mozjpeg is disabled as it causes errors in some Linux environments
                // Try enabling it in your environment by switching the config to:
                // enabled: true,
                // progressive: true,
              },
              gifsicle: {
                interlaced: false,
              },
              optipng: {
                optimizationLevel: 7,
              },
              pngquant: {
                quality: '65-90',
                speed: 4,
              },
            },
          },
        ],
      },
      {
        test: /\.html$/,
        use: 'html-loader',
      },
      {
        test: /\.(mp4|webm)$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 10000,
          },
        },
      },
    ],
  },
  plugins: options.plugins.concat([
    // Always expose NODE_ENV to webpack, in order to use `process.env.NODE_ENV`
    // inside your code for any environment checks; Terser will automatically
    // drop any unreachable code.
    new webpack.EnvironmentPlugin({
      NODE_ENV: 'development',
      VERSION: version,
    }),
    // Run typescript checker
    new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true }),
    new Dotenv({
      path: './.env',
      expand: true,
    }),
    new CopyPlugin({
      patterns: [{ from: 'public', to: './' }],
    }),
    new WebpackRequireFrom({
      path: 'XXXXX/',
    }),
  ]),
  resolve: {
    modules: ['node_modules', 'app'],
    extensions: ['.js', '.jsx', '.react.js', '.ts', '.tsx'],
    alias: {
      'react-dom': '@hot-loader/react-dom',
    },
  },
  devtool: options.devtool,
  target: 'web', // Make web variables accessible to webpack, e.g. window
  performance: options.performance || {},
});

  • Result in index.html file
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="mobile-web-app-capable" content="yes"/><link rel="icon" href="favicon.ico"/><title>React boiler plate</title></head><body><noscript>If you're seeing this message, that means <strong>JavaScript has been disabled on your browser</strong>, please <strong>enable JS</strong> to make this app work.</noscript><div id="app"></div><link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet"/><script src="/webpack/runtime.8d93c084f826a62e6fae.js"></script><script src="/webpack/npm.react-intl.2a71e314f7b1ae52c2d2.chunk.js"></script><script src="/webpack/npm.core-js.261cb4663f0f7dbcc11a.chunk.js"></script><script src="/webpack/npm.material-ui.be0e69599d42f7db22d0.chunk.js"></script><script src="/webpack/npm.moment.ed6b7f4182227f916bf2.chunk.js"></script><script src="/webpack/npm.lodash.1a583cd11913972ba20d.chunk.js"></script><script src="/webpack/npm.formatjs.168e619a0b5d78aaf4c4.chunk.js"></script><script src="/webpack/npm.axios.e165c46e0226587b8c0b.chunk.js"></script><script src="/webpack/npm.babel.252f73c7da3408fe1aa1.chunk.js"></script><script src="/webpack/npm.react-redux.7724d467b66e174dd0b2.chunk.js"></script><script src="/webpack/main.

webpack v5: doesn't work

Unfortunately seems that this plugin doesn't work on webpack v5.

Uncaught TypeError: __webpack_modules__[moduleId] is not a function
    at __webpack_require__

Bundle code portion:

/******/ 	// WebpackRequireFrom
/******/ 	Object.defineProperty(__webpack_require__, "p", {
/******/ 	  get: function () {
/******/ 	try {
/******/ 	  if (typeof REQUIRE_BASE_URL !== "string") {
/******/ 	    throw new Error("WebpackRequireFrom: 'REQUIRE_BASE_URL' is not a string or not available at runtime. See https://github.com/agoldis/webpack-require-from#troubleshooting");
/******/ 	  }
/******/ 	  return REQUIRE_BASE_URL;
/******/ 	} catch (e) {
/******/ 	  if (!false) {
/******/ 	    console.error(e);
/******/ 	  }
/******/ 	  return "auto";
/******/ 	}
/******/ 	 }
/******/ 	})/* webpack/runtime/jsonp chunk loading */
/******/ 	(() => {

Probably it's something very silly like a missing semicolon on the defineProperty call.

Can you add documentation about how to use this?

Hi I have the use case where the CDN url is different from staging and production but there is not documentation about how to handle that use case. Could you explain how to use your plugin?
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.