gpt4 book ai didi

javascript - 如何捆绑除指定需求之外的 commonjs 模块

转载 作者:行者123 更新时间:2023-12-02 14:38:04 26 4
gpt4 key购买 nike

如何通过 webpack 或 gulp+browserify 进行捆绑,除非指定需要,例如忽略 var module = require(pathToModule);因此,生成的 bundle 还包含 var module = require(pathToModule);

最佳答案

这可以通过 webpack externals option 来完成

You can use the externals options for applications too, when you want to import an existing API into the bundle. I.e. you want to use jquery from CDN (separate <script> tag) and still want to require("jquery") in your bundle. Just specify it as external: { externals: { jquery:
"jQuery" } }
.

webpack.config

{
externals: {
// require("jquery") is external and available
// on the global var jQuery
"jquery": "jQuery"
}
}
<小时/>

如果你希望 webpack 忽略外部模块并在输出中保留 require 语句,你可以使用空加载器

loaders: [{
test: /@amperka\/.*/,
loader: 'null'
}

关于javascript - 如何捆绑除指定需求之外的 commonjs 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37264125/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com