ProvidePlugin
모ëì import ëë require í íì ìì´ ìëì¼ë¡ ë¡ëí©ëë¤.
new webpack.ProvidePlugin({
identifier: "module1",
// ...
});ëë
new webpack.ProvidePlugin({
identifier: ["module1", "property1"],
// ...
});기본ì ì¼ë¡, 모ë í´ì ê²½ë¡ë íì¬ í´ë (./**)ì node_modulesì
ëë¤.
ëí ì ì²´ ê²½ë¡ë ì§ì í ì ììµëë¤.
import path from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
new webpack.ProvidePlugin({
identifier: path.resolve(path.join(__dirname, "src/module1")),
// ...
});모ëìì ìì ë³ìë¡ ìë³ì를 ë§ë ëë§ë¤ 모ëì´ ìëì¼ë¡ ë¡ëëê³ , ìë³ìê° ë¡ëë 모ëì exports(í¹ì ì§ì ë exports를 ë기 ìí íë¡í¼í°)ë¡ ì±ìì§ëë¤.
ES2015 모ëì 기본 export를 ê°ì ¸ì¤ë ¤ë©´ 모ëì 기본 íë¡í¼í°ë¥¼ ì§ì í´ì¼ í©ëë¤.
Usage: jQuery
jquery를 ìëì¼ë¡ ë¡ëíë ¤ë©´ í´ë¹ ë
¸ë 모ëì ë
¸ì¶ëë ë ë³ì를 모ë ê°ë¦¬í¬ ì ììµëë¤.
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
});ìì¤ ì½ë ì¤ ì´ë ê²ì´ë¼ë ëì¼í©ëë¤.
// 모ëìì
$("#item"); // <= ëìí©ëë¤.
jQuery("#item"); // <= ì´ ëí ëìí©ëë¤.
// $ë 모ë "jquery" exportsë¡ ìë ì¤ì ëììµëë¤.Usage: jQuery with Angular 1
Angularë jQueryê° ì¡´ì¬íëì§ ì°¾ê¸° ìí´ window.jQuery를 ì°¾ìµëë¤. ìì¤ ì½ë를 ì°¸ê³ íì¸ì.(https://github.com/angular/angular.js/blob/v1.5.9/src/Angular.js#L1821-L1823).
new webpack.ProvidePlugin({
"window.jQuery": "jquery",
});Usage: Lodash Map
new webpack.ProvidePlugin({
_map: ["lodash", "map"],
});Usage: Vue.js
new webpack.ProvidePlugin({
Vue: ["vue/dist/vue.esm.js", "default"],
});


