[英]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: 这种方法是否正确尚不能确定,但是我解决了:
Installed bootstrap-webpack
: npm install bootstrap-webpack --save-dev
安装的
bootstrap-webpack
: npm install bootstrap-webpack --save-dev
Installed expose-loader
: npm install expose-loader --save-dev
安装的
expose-loader
: npm install expose-loader --save-dev
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'}
require
on top of main index.js
after imports: index.js
顶部添加了require
: Code: 码:
require('expose?$!expose?jQuery!jquery');
require("bootstrap-webpack");
您只是在main.js中错过了这段代码
import 'bootstrap'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.