Allow Dynamic Import in commonjs2
#16272
-
Feature requestWhat is the expected behavior? Furthermore, dynamic What is motivation or use case for adding/changing the behavior? Despite this fact, How should this be implemented in your opinion? Furthermore, adding a Are you willing to work on this yourself? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 17 replies
-
|
Do you looking for https://webpack.js.org/configuration/externals/#externalstype, i.e. |
Beta Was this translation helpful? Give feedback.
-
|
I find it odd that I have to write specific exception code every time I want to use a dynamic import If I add import('@ant-design/cssinjs') now I need: const ext = nodeExternals({
allowlist: [/@babel\/runtime/],
additionalModuleDirs: ['../../node_modules'],
});
config.externals = [
function ({ context, request, contextInfo, getResolve }, callback) {
if (request === '@ant-design/cssinjs') {
callback(null, 'import ' + request);
} else ext({ context, request, contextInfo, getResolve }, callback);
},
];Then if I decide to add another one, I'll have to add it to this list. Furthermore, that means that if I don't use a dynamic import it won't actually work as expected. What's odd is that, if the environment supports dynamicImport - there's no reason to ever transform it. Why do the extra work and force everyone to do super hyper-specific configurations? Just leave it alone and everything works fine. |
Beta Was this translation helpful? Give feedback.
-
|
Is there some way to flag a dependency as Consider the following code: import { createRequire } from "node:module";
import puppeteer from "puppeteer"; // I want to import the ESM version of `puppeteer` here
const anotherPuppeteer = createRequire(new URL(".", import.meta.url)("puppeteer"); // At some other place - in another source file, by chance, I want to import the CommonJS version of `puppeteer`Is there some way to tell webpack that That would be a great feature as you probably want to import the module exactly as you stated it in your code. |
Beta Was this translation helpful? Give feedback.
Do you looking for https://webpack.js.org/configuration/externals/#externalstype, i.e.
import?