javascript - WebPack replace vendor require call with global variable -
having trouble webpack. have vendor library (saying childvendor), implements requirejs , commonjs compatibility, so, need require in webpack project var lib = require('./childvendor');. childvendor library has dependency (saying supervendor), , both of them requirejs- , commonjs-adapted, so, heading of childvendor.js looks like:
(function(root, factory) { if (typeof define === 'function' && define.amd) { define(["supervendor"], factory); } else if (typeof exports === 'object') { module.exports = factory(require('supervendor')); } else { root.shepherd = factory(root.supervendor); } }(this, function(supervendor) { /*...*/ })); the main problem need include supervendor library globally on html-file manually (so, initialized window.supervendor), because should used other third-party libraries.
to solve this, have tried webpack.provideplugin, like
plugins: [ new webpack.provideplugin({ 'supervendor': 'supervendor' }) ], but error still same (module not found: error: can't resolve 'supervendor' in '...').
provideplugin not solution want do. configuration you've set tells webpack:
whenever
supervendorencountered free variable in module, load modulesupervendor, set variablesupervendorexportedsupervendor.
in other words if have module contains this:
supervendor.somemethod(); webpack interprets if were:
var supervendor = require("supervendor"); supervendor.somemethod(); what should use externals configuration option:
externals: { 'supervendor': 'supervendor' } this tells webpack if module supervendor required should sought external environment name supervendor.
Comments
Post a Comment