[英]How do I prevent webpack from rewriting import() so that I can use the buildIn one?
I am writing a kind of meta application.我正在编写一种元应用程序。 It is written in React and bundled by webpack.
它是用 React 编写的,由 webpack 打包。 The meta application loads a .js file based on the user input etc. The .js file may not exist at the bundling time.
元应用程序根据用户输入等加载 .js 文件。 .js 文件在捆绑时可能不存在。 My loading function should just make an HTTP(S) request, try to load the file, and take a function with a known name in the file.
我的加载函数应该只是发出一个 HTTP(S) 请求,尝试加载文件,然后在文件中使用一个已知名称的函数。
If I just have import(aConstructedPath})
in my loading function, webpack treats it as its directive and generates something like __webpack_require__("./ lazy recursive ^.*$")...
.如果我的加载函数中只有
import(aConstructedPath})
,webpack 会将其视为其指令并生成类似__webpack_require__("./ lazy recursive ^.*$")...
。 How can just just say that this import()
should use the built-in one?怎么能只说这个
import()
应该使用内置的呢?
I am not sure if you have defined import already.我不确定您是否已经定义了导入。 But you can give it a try if you have
但是如果你有的话,你可以试一试
const anyName = eval(`import(${aConstructedPath})`);
Where anyName is imported package.其中 anyName 是导入包。
This will make webpack not to rename the code inside ``这将使 webpack 不会重命名里面的代码``
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.