首页 > 解决方案 > 将引导程序添加到 webpack。为什么第二种方法不起作用

问题描述

只有它对我有用

在 js scrypts 中添加:

import $ from 'jquery';
global.jQuery = $;
global.$ = $;

import Popper from 'popper.js'
global.Popper = Popper

import 'bootstrap'

// there $.fn defined anyway
// and in chrome console too (in first way)

第二种方式(不工作):

// ! comment this strings
// import $ from 'jquery';
// global.jQuery = $;
// global.$ = $;
// after bootstrap importing add

 console.log($.fn) // Object, defined   
 // past it in console after execution - it will undefined

// add in config
plugins: [
     new webpack.ProvidePlugin(
        {
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
            'global.jQuery': 'jquery',
            'global.$': 'jquery',
        },
     ),
...

但是如果做更低的方式,我不知道为什么,在 scrypt 的控制台结束时,$.fn 未定义。它看起来像控制台和 webpack 构建中使用的其他 $ 示例。有人可以解释一下吗?

有这个构建回购克隆

标签: webpackbootstrap-4

解决方案


推荐阅读