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

Allow paths replacement for webpack 5 #63

Open
agoldis opened this issue Apr 23, 2021 · 3 comments
Open

Allow paths replacement for webpack 5 #63

agoldis opened this issue Apr 23, 2021 · 3 comments

Comments

@agoldis
Copy link
Owner

agoldis commented Apr 23, 2021

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

@CharphDang
Copy link

Hi agoldis @agoldis ,

any update for this issue ?

Best regards

@harshith-m-verse
Copy link

Hi @agoldis , did you find any solution to use our custom function for 'replaceSrcMethodName' in webpack 5?

@LeifAndersen
Copy link

FWIW, you can make your own custom loader which uses a global function...similar to replaceSrcMethodName. For example, if you make the file dynamic-loader.js with the following contents:

const path = require('path');

module.exports = function (src) {
    return "export default visr_dynamic_load('" +
        path.relative(__dirname, this.resourcePath)
        + "');";
}

You can now refer to that loader in your webpack config (in the module.rules block):

            {
                test: /\.wasm$/,
                type: "javascript/auto",
                loader: path.resolve("dynamic-loader.js")
            },

This expects a function visr_dynamic_load in your global namespace that takes the path to the asset (as a string), and returns the URL for that asset (also as a string).

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

4 participants