1
This commit is contained in:
115
demo-project/webpack.config.js
Normal file
115
demo-project/webpack.config.js
Normal file
@@ -0,0 +1,115 @@
|
||||
const path = require('path')
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
||||
const { VueLoaderPlugin } = require('vue-loader')
|
||||
|
||||
module.exports = (env, argv) => {
|
||||
const isDevelopment = argv.mode === 'development'
|
||||
|
||||
return {
|
||||
entry: './src/main.js',
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
filename: isDevelopment ? 'bundle.js' : 'bundle.[contenthash:8].js',
|
||||
clean: true
|
||||
},
|
||||
// 开发模式使用高质量的 source map,方便调试
|
||||
devtool: isDevelopment ? 'eval-source-map' : 'source-map',
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.vue$/,
|
||||
loader: 'vue-loader'
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'babel-loader',
|
||||
exclude: /node_modules/
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
'vue-style-loader',
|
||||
{
|
||||
loader: 'css-loader',
|
||||
options: {
|
||||
sourceMap: isDevelopment
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.less$/,
|
||||
use: [
|
||||
'vue-style-loader',
|
||||
{
|
||||
loader: 'css-loader',
|
||||
options: {
|
||||
sourceMap: isDevelopment
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: 'less-loader',
|
||||
options: {
|
||||
sourceMap: isDevelopment
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
|
||||
loader: 'url-loader',
|
||||
options: {
|
||||
limit: 10000,
|
||||
name: 'images/[name].[hash:7].[ext]',
|
||||
esModule: false
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
||||
loader: 'url-loader',
|
||||
options: {
|
||||
limit: 10000,
|
||||
name: 'fonts/[name].[hash:7].[ext]',
|
||||
esModule: false
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new VueLoaderPlugin(),
|
||||
new HtmlWebpackPlugin({
|
||||
template: './public/index.html',
|
||||
filename: 'index.html'
|
||||
})
|
||||
],
|
||||
resolve: {
|
||||
extensions: ['.js', '.vue', '.json'],
|
||||
alias: {
|
||||
// 框架源码的别名(必须在前面,优先级高)
|
||||
'@': path.resolve(__dirname, '../src'),
|
||||
'@component': path.resolve(__dirname, '../src/components'),
|
||||
'@utils': path.resolve(__dirname, '../src/utils'),
|
||||
'@api': path.resolve(__dirname, '../src/api'),
|
||||
'@config': path.resolve(__dirname, '../src/config'),
|
||||
'@assets': path.resolve(__dirname, '../src/assets'),
|
||||
// demo 项目的别名
|
||||
'~': path.resolve(__dirname, 'src'),
|
||||
'vue$': 'vue/dist/vue.esm.js'
|
||||
}
|
||||
},
|
||||
devServer: {
|
||||
port: 8080,
|
||||
hot: true,
|
||||
open: true,
|
||||
historyApiFallback: true,
|
||||
// 启用覆盖层显示编译错误
|
||||
client: {
|
||||
overlay: {
|
||||
errors: true,
|
||||
warnings: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user