有没有办法禁用 AMDPlugin? [英] Is there a way to disable AMDPlugin?

查看:28
本文介绍了有没有办法禁用 AMDPlugin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Webpack 默认包含 AMDPlugin,因此如果模块在 CommonJS 之前检查 AMD,将使用该模块定义.

Webpack includes AMDPlugin by default, so if a module checks for AMD before CommonJS, that module definition will be used.

if (typeof define === 'function' && define.amd) {
  define([], factory)
} else if (typeof exports === 'object') {
  exports.foo = factory();
}

我想完全忽略 AMD.有没有办法在 webpack 中做到这一点?

I would like to ignore AMD altogether. Is there a way to do it in webpack?

推荐答案

可以用imports-loader<解决/a>

It can be solved with imports-loader

在使用 CommonJS 之前,有许多模块会检查定义函数.由于 webpack 两者都具备,因此在这种情况下它们默认为 AMD,如果实现很古怪,这可能是一个问题.然后你可以很容易地通过编写

There are many modules that check for a define function before using CommonJS. Since webpack is capable of both, they default to AMD in this case, which can be a problem if the implementation is quirky. Then you can easily disable the AMD path by writing

imports?define=>false

简单的做

require('imports?define=>false!myjsfile.js')

更好的方法是在 webpack.config.js 中添加加载器

OR a better approach is in webpack.config.js you add a loader

loaders: [ { test: /myjsfile.js/, loader: 'imports?define=>false'} ]

这篇关于有没有办法禁用 AMDPlugin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆