安装淘宝镜像:
npm install -g cnpm --registry=https://registry.npm.taobao.org
安装webpack:
cnpm install webpack -g
安装vue脚手架:
npm install vue-cli -g
在D盘下新建目录:demo,并在该文件夹下新建项目vue-example:
d:
cd demo
vue init webpack-simple vue-example
CD命令进入vue-example
cd vue-example
安装项目依赖
npm install
安装 vue 路由模块vue-router和网络请求模块vue-resource
cnpm install vue-router vue-resource --save
启动项目
npm run dev
在src/assets下面新建css、js、less、fonts文件夹,并放入对应文件。
将bootstrap.css放入css目录下,bootstrap.min.js放入js文件下,fonts字体放入fonts目录下.
安装js依赖
cnpm install jquery --save-dev
安装css依赖
cnpm install style-loader --save-dev
cnpm install css-loader --save-dev
cnpm install file-loader --save-dev
安装less依赖
npm install less less-loader --save
修改webpack.base.conf.js文件,让其支持外部的css和js
module.exports = { entry: { app:'./src/main.js'},
后面加
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"windows.jQuery": "jquery"
})
],
把
alias: {'vue$':'vue/dist/vue.common.js','src': path.resolve(__dirname,'../src'),'assets': path.resolve(__dirname,'../src/assets'),'components': path.resolve(__dirname,'../src/components')}
改成
alias: {
'vue$': 'vue/dist/vue.common.js',
'src': path.resolve(__dirname, '../src'),
'assets': path.resolve(__dirname, '../src/assets'),
'components': path.resolve(__dirname, '../src/components'),
jquery: "jquery/src/jquery"
}
修改webpack.base.conf.js文件,配置loader加载依赖,让其支持外部的css和js,less
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
loader: "style-loader!css-loader",
},
{
test: /\.less$/,
loader: "style-loader!css-loader!less-loader",
},
修改webpack.base.conf.js文件,配置字体loader加载依赖,让其支持字体图标
{test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader?mimetype=image/svg+xml'},
{test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/font-woff"},
{test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/font-woff"},
{test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader?mimetype=application/octet-stream"},
{test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader"}
接着修改 src文件夹下面的main.js文件,打开文件之后在顶部加入
import'./assets/css/bootstrap.css'
import'./assets/js/bootstrap.min.js'
import'./assets/less/less.less'