[英]Dynamically loading webpack common chunks in browser (with requirejs)
I'm trying to create a Webpack bundle with some "vendor" dependencies (React, lodash, ...) and use them in my web app. 我正在尝试创建具有某些“供应商”依赖项(React,lodash等)的Webpack捆绑包,并在我的Web应用程序中使用它们。
The issue I have, is that I don't want to add my vendor.js file as a <script>
tag to my page, but rather require
or import
it in some way. 我遇到的问题是,我不想将我的vendor.js文件作为
<script>
标记添加到页面中,而是require
或以某种方式import
它。
I tried using requirejs , but an error keeps coming up saying 我尝试使用requirejs ,但出现错误提示
webpackjsonp is undefined
webpackjsonp未定义
Now, from what I read webpackJsonp is defined by CommonsChunkPlugin, which disallows loading scripts with async
attribute. 现在,从我读到的webpackJsonp是由CommonsChunkPlugin定义的,它不允许加载具有
async
属性的脚本。
My question : how can I dynamically load dependencies (vendors.js, commons.js, ...) only when they are required , while still using webpack? 我的问题 : 如何仅在需要时动态加载依赖项(vendors.js,commons.js等) ,而仍然使用webpack?
More info: I use Typescript for my development, which loads modules using commonjs configuration (eg: import {clone} from "lodash/clone"
) 更多信息:我在开发中使用Typescript,该脚本使用commonjs配置加载模块(例如:
import {clone} from "lodash/clone"
)
Thank you in advance. 先感谢您。
您可以使用webpack内置代码拆分 require.ensure
或import()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.