简体   繁体   English

在webpack中包含bootstrap js模块

[英]Include bootstrap js modules in webpack

I successfully use this bootstrap CSS and fonts but dropdowns not work and I can't see any errors in console so I can't debug the issue. 我已成功使用此引导 CSS和字体,但下拉菜单不起作用,并且在控制台中看不到任何错误,因此无法调试问题。 Seems like I need to do something to include dropdown.js from node_modules\\bootstrap\\js\\ , but how to do this in "webpacking" way? 似乎我需要做一些事情来包括来自node_modules\\bootstrap\\js\\ dropdown.js ,但是如何以“ webpacking”方式做到这一点?

package.json: package.json:

  ...
  "dependencies": {
    "bootstrap": "*",
    "jquery": "*",
    "vue-resource": "*",
    "vue-router": "*",
    "vue": "*"
  }
  ...

webpack.config.js webpack.config.js

module.exports = {
    // the main entry of our app
    entry: ['./src/index.js', './src/auth/index.js'],
    // output configuration
    output: {
        path: __dirname + '/build/',
        publicPath: 'build/',
        filename: 'build.js'
    },

    module: {
        loaders: [
            // process *.vue files using vue-loader
            {test: /\.vue$/, loader: 'vue'},
            // process *.js files using babel-loader
            // the exclude pattern is important so that we don't
            // apply babel transform to all the dependencies!
            {test: /\.js$/, loader: 'babel', exclude: /node_modules/}
        ]
    },

    devServer: {
        headers: {"Access-Control-Allow-Origin": "*"}
    },

    babel: {
        presets: ['es2015'],
        plugins: ['transform-runtime']
    }
}

Some manuals describe how to use another package bootstrap-webpack . 一些手册描述了如何使用另一个软件包bootstrap-webpack I can't understand what the difference, and do I also need use that package insted of bootstrap from twbs 我不明白有什么区别,我是否还需要使用从twbs插入的引导程序包

Not shure is this way correct or not, but I solved it: 这种方法是否正确尚不能确定,但​​是我解决了:

  1. Installed bootstrap-webpack : npm install bootstrap-webpack --save-dev 安装的bootstrap-webpacknpm install bootstrap-webpack --save-dev

  2. Installed expose-loader : npm install expose-loader --save-dev 安装的expose-loadernpm install expose-loader --save-dev

  3. Added loaders: 增加的装载机:

to webpack.config.js module: { loaders: [ : webpack.config.js module: { loaders: [

// the url-loader uses DataUrls.
// the file-loader emits files.
{test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff'},
{test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream'},
{test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file'},
{test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml'}
  1. Added require on top of main index.js after imports: 导入后在main index.js顶部添加了require

Code: 码:

require('expose?$!expose?jQuery!jquery');
require("bootstrap-webpack");

您只是在main.js中错过了这段代码

 import 'bootstrap' 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用webpack包含引导程序 - Include bootstrap using webpack Webpack 不制作 JS 模块 - Webpack not making JS modules 如何修复“BREAKING CHANGE: webpack < 5 used to include polyfills for default core modules”错误? - How fix "BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default" error? webpack < 5 用于默认包含 node.js 核心模块的 polyfill。 这已不再是这种情况 - webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case Webpack esm 模块解析“警告 in../node_modules/react-bootstrap/esm/index.js” - Webpack esm module resolve “WARNING in ../node_modules/react-bootstrap/esm/index.js” 当我添加 package 时,我收到 webpack &lt; 5 用于默认包含 node.js 核心模块的 polyfills。现在不再是这种情况 - when i add a package i recieve webpack < 5 used to include polyfills for node.js core modules by default.This is no longer the case 未找到模块:错误:无法解析“crypto”,webpack < 5 默认用于包含 node.js 核心模块的 polyfill - Module not found: Error: Can't resolve 'crypto', webpack < 5 used to include polyfills for node.js core modules by default Bootstrap JS未在Webpack的React中加载 - Bootstrap JS not loading in React with Webpack Webpack 无法解析 Node.js 模块 - Webpack cannot resolve Node.js modules webpack loader总是在编译中包含node_modules - webpack loader always include node_modules in compilation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM