例子中css文件採用bootstrap.css,js文件採用jQuery,less文件用less.less(自定義文件)css
步驟一:安裝webpackvue
cnpm install webpack -gnode
步驟二:在src/assets下面新建css、js、less、fonts文件夾,並放入對應文件。jquery
將bootstrap.css放入css目錄下,bootstrap.min.js放入js文件下,fonts字體放入fonts目錄下webpack
步驟三:安裝js依賴web
cnpm install jquery --save-devnpm
步驟四:安裝css依賴bootstrap
cnpm install style-loader --save-devbabel
cnpm install css-loader --save-devapp
cnpm install file-loader --save-dev
步驟五:安裝less依賴
npm install less less-loader --save
步驟六:修改build/webpack.base.conf.js文件,
(1)在開頭引入webpack(後面的plugins那裏須要)
var webpack = require('webpack')
(2)添加jquery插件,
在module.exports = { entry: {app:'./src/main.js'},
後面加
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
],
(3)設置路徑,
把resolve裏面的
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"
}
(4)配置loader加載依賴,
在修改module裏面
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
loader: "style-loader!css-loader",
},
{
test: /\.less$/,
loader: "style-loader!css-loader!less-loader",
},
(5)配置字體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'
如今就可以使用less、jquery,以下圖所示: