package.json
{
"name": "wp-study",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack-dev-server --contentBase src --open --hot",
"build": "webpack --config webpack.config.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"vue": "^2.5.22"
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/plugin-transform-classes": "^7.2.2",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/plugin-transform-strict-mode": "^7.2.0",
"@babel/preset-env": "^7.2.3",
"@babel/runtime": "^7.2.0",
"babel-loader": "^8.0.5",
"babel-plugin-component": "^1.1.1",
"css-loader": "^2.1.0",
"file-loader": "^3.0.1",
"html-webpack-plugin": "^3.2.0",
"less": "^3.9.0",
"less-loader": "^4.1.0",
"node-sass": "^4.11.0",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"url-loader": "^1.1.2",
"vue-loader": "^15.5.1",
"vue-template-compiler": "^2.5.22",
"webpack": "^4.28.4",
"webpack-cli": "^3.2.1",
"webpack-dev-server": "^3.1.14"
}
}
webpack.congfig.js
const path = require('path');
// 引入html-webpack-plugin
const htmlWebpackPlugin=require('html-webpack-plugin');
// 热更新第二步
const webpack=require('webpack');
// vue-loader插件
const { VueLoaderPlugin } = require('vue-loader');
module.exports = {
mode: 'development', //production
entry: path.resolve(__dirname, './src/main.js'),
// entry:["@babel/polyfill",path.resolve(__dirname, './src/main.js')],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
// webpack-dev-server的配置节点
devServer:{
open:true, //自动打开浏览器
port:3000, //指定端口
contentBase:'src', //指定服务器名根目录
hot:true, //热更新第一步
progress:false, //显示打包进度
quiet:false,
proxy: {
'/api': {
target: 'http://www.duans.top/freeApi',
pathRewrite: {'^/api' : ''},
changeOrigin: true, // target是域名的话,需要这个参数,
secure: false
}
}
},
plugins:[
// 热更新第三步
new webpack.HotModuleReplacementPlugin(),
new htmlWebpackPlugin({
template:path.join(__dirname,'src/index.html'), //模板文件的目录+文件名
filename:'index.html' //内存中的文件名
}),
// vue-loader插件
new VueLoaderPlugin()
],
module:{
rules:[
// css打包配置
{test:/\.css$/,use:['style-loader','css-loader']},
// less配置
{test:/\.less$/,use:['style-loader','css-loader','less-loader']},
//打包scss
{test:/\.scss$/,use:['style-loader','css-loader','sass-loader']},
//打包图片
{
test:/\.(png|gif|jpg|jpeg|bmp)$/,
use:'url-loader?limit=2048U&name=[hash:8]-[name].[ext]'
},
//打包字体文件
{
test:/\.(ttf|eot|svg|woff|woff2|otf)$/,
use: 'url-loader'
},
//babel配置
{
test:/\.js$/,
use:'babel-loader',
exclude:['/node_modules/'] //不需要转换的js文件
},
//打包.vue
{
test:/\.vue$/,
use:'vue-loader'
}
]
},
resolve:{
alias:{
"vue$":"vue/dist/vue.js"
}
}
};
.babelrc
{
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-classes",
"@babel/plugin-transform-strict-mode"
],
"ignore":[
"./src/lib/mui/js/*.js"
]
}
网友评论