安装Vue
# 安装vue脚手架
$ npm i vue-cli -g
# 创建vue项目
$ vue init webpack vuk
# 安装基础包
$ cd vuk && npm i
# 运行项目
$ vue run dev
安装配置jQuery
$ npm i jquery -D
# build/webpack.base.config.js
'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
// 引入webpack
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'),
'ukcss$':'uikit/dist/css/uikit-rtl.min.css'
}
},
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: {
setImmediate: false,
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
},
//插件
plugins:[
new webpack.ProvidePlugin({
$:'jquery',
jQuery:'jquery',
jquery:'jquery',
'window.jQuery':'jquery',
})
]
}
# src/main.js
import $ from 'jquery'
安装 UIkit
# 安装UIkit
$ npm i jquery uikit -D
# 配置UIkit
# src/main.js
import 'jquery'
import 'uikit'
import 'ukcss'
# webpack中配置UIkit的样式引用别名
# build/webpack.config.js
resolve:{
alias:{
'ukcss$':'uikit/dist/css/uikit-rtl.min.css'
}
}
# 制作UIkit的Vue插件
$ vim src/uikit.js
imort 'jquery'
import 'uikit'
import 'ukcss'
export default (Vue, options) {
// 向实例注入UIkit对话框类方法
Vue.prototype.$ui = {
alert:UIkit.modal.alert,
confirm:UIkit.modal.confirm,
prompt:UIkit.modal.prompt,
block:UIkit.modal.block
}
}
# 入口文件中载入插件
$ vim src/main.js
import UIkit from './uikit'
Vue.use(UIkit)
Vuikit
$ npm i vue
$ npm i vuikit
$ npm i @vuikit/icons
$ npm i @vuikit/theme