vue-cli 引入jQuery,Bootstrap,popper的方法
作者:ln0909 时间:2024-05-21 10:17:21
1.安装插件
npm install jquery --save //jquery插件
npm install bootstrap --save //bootstrap
npm install --save popper.js //popper.js
2.修改build目录下的webpack.base.conf.js配置文件:
1)加入webpack对象:var webpack=require('webpack');
2)在module.exports里面加入以下配置:
plugins: [
new webpack.optimize.CommonsChunkPlugin('common'),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Popper: ['popper.js', 'default']
})
]
webpack.base.conf.js配置文件最终代码
'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
const webpack = require('webpack')
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
module.exports = {
context: path.resolve(__dirname, '../'),
entry: {
app: './src/main.js'
},
output: {
path: config.build.assetsRoot,
filename: '[name].js',
publicPath: process.env.NODE_ENV === 'production'
? config.build.assetsPublicPath
: config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
}
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
},
node: {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('common'),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Popper: ['popper.js', 'default']
})
]
}
3.在main.js中把jQuery,bootstrap的js和css通过import引进来
代码如下:
import $ from 'jquery'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/js/bootstrap.min'
最后重新启动一下:
npm run dev
来源:https://segmentfault.com/a/1190000016232294
标签:vue-cli,jQuery,Bootstrap,popper
0
投稿
猜你喜欢
Python中设置变量作为默认值时容易遇到的错误
2023-09-14 09:32:00
如果没设置 DSN 也能建立数据库连接吗?
2009-11-02 20:16:00
JS实现网页滚动条感应鼠标变色的方法
2024-04-18 10:52:44
tensorflow TFRecords文件的生成和读取的方法
2022-04-04 23:21:05
貌似很强的mysql备份策略分享
2024-01-27 18:37:03
python 处理telnet返回的More,以及get想要的那个参数方法
2023-02-09 11:32:14
特征脸(Eigenface)理论基础之PCA主成分分析法
2023-03-03 07:19:33
基于微信小程序实现透明背景人像分割功能
2024-06-05 09:34:50
sql在一个表中添加字段并添加备注的方法
2024-01-26 10:16:59
Python破解BiliBili滑块验证码的思路详解(完美避开人机识别)
2022-08-23 06:39:23
Python学习之字典和集合的使用详解
2022-11-01 19:54:21
浅谈python中的多态
2022-09-13 16:45:40
Javascript+XMLHttpRequest+asp.net无刷新读取数据库数据
2024-01-17 17:32:18
Python创建系统目录的方法
2023-11-22 11:52:47
python中文乱码不着急,先看懂字节和字符
2023-08-25 05:27:55
ERROR CODE: 1175 YOU ARE USING SAFE UPDATE MODE AN
2024-01-17 21:57:50
python的移位操作实现详解
2021-05-05 22:51:30
pytorch中如何设置随机种子
2021-10-24 06:43:51
Python使用tkinter实现摇骰子小游戏功能的代码
2021-03-18 09:15:16
Python使用三种方法实现PCA算法
2022-06-26 13:32:49