简体   繁体   English

如何防止 webpack 重写 import() 以便我可以使用 buildIn one?

[英]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.

相关问题 如何阻止Internet Explorer重写我的文本? - How do I prevent internet explorer from rewriting my text? 我如何将 fonts 从谷歌 fonts 导入 javascript,这样我就可以将它用于我的 ZFCC790C72A86190DE - How would I import fonts from google fonts into javascript, so i can use it for my canvas? 如何通过webpack导入引导程序? - How do I import bootstrap via webpack? Webpack + Babel 正在转译 Webpack 加载器,我该如何防止? - Webpack + Babel is transpiling Webpack loaders, how do I prevent this? 如何使用 array.push() 方法,以便将数据从一个组件推送到单独文件中的数组中? - How do I can I use the array.push() method, so I can push data from one component into an array in a seperate file? 使用angular 2 CLI,如何使用绝对路径,所以不必使用来自'../../../shared/thing'的import {..} - using angular 2 CLI, how can I use absolute paths so I don't have to use import { .. } from '../../../shared/thing' 如何使用webpack从Windows使用jQuery? - How do I use jQuery from windows using webpack? 为什么我的LastPass浏览器扩展程序至少应该为此页面添加autocomplete = off,并且如何防止这样做? - Why is autocomplete=off being supposedly added by my LastPass browser extension for this one page at least, and how can I prevent it from doing so? d3.js choropleth映射-如何将多个属性从CSV映射到JSON,以便可以在工具提示中使用它? - d3.js choropleth map --How do I map more than one property from CSV to JSON, so I can use it in a tooltip? 如何使用postcss-import和Webpack 2导入导入的文件? - How can I import imported files with postcss-import and Webpack 2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM