Is there a way to disable AMDPlugin?

前端 未结 3 774
余生分开走
余生分开走 2021-01-01 16:04

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

if (typeof define === \'function\'         


        
相关标签:
3条回答
  • It can be solved with imports-loader

    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

    Simply do

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

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

    loaders: [ { test: /myjsfile.js/, loader: 'imports?define=>false'} ]
    
    0 讨论(0)
  • 2021-01-01 16:52

    You can also add to the following to your rules to disable AMD(webpack 2+):

    module: {
        rules: [
            { parser: { amd: false } }
        ]
    }
    

    From: https://webpack.js.org/configuration/module/

    0 讨论(0)
  • 2021-01-01 16:57

    Also consider script-loader, as mentioned at the end of the Shimming documentation:

    The script-loader evaluates code in the global context, similar to inclusion via a script tag. In this mode, every normal library should work. require, module, etc. are undefined.

    0 讨论(0)
提交回复
热议问题