Files
pig-farm-controller-fe/webpack.config.js
2025-10-01 00:29:21 +08:00

75 lines
1.8 KiB
JavaScript

const { VueLoaderPlugin } = require('vue-loader');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack'); // 引入 webpack 模块
module.exports = (env, argv) => {
const isDevelopment = argv.mode === 'development';
return {
entry: './src/main.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
clean: true,
publicPath: '/'
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
]
},
plugins: [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template: './index.html',
filename: 'index.html'
}),
// 添加 Vue 特性标志的定义
new webpack.DefinePlugin({
__VUE_OPTIONS_API__: JSON.stringify(true),
__VUE_PROD_DEVTOOLS__: JSON.stringify(isDevelopment),
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(isDevelopment)
})
],
devServer: {
static: {
directory: path.join(__dirname, 'dist'),
},
hot: true,
open: true,
historyApiFallback: true,
port: 8080,
proxy: {
'/api': {
target: 'http://localhost:8086',
changeOrigin: true,
secure: false
}
}
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'vue': '@vue/runtime-dom'
},
extensions: ['.js', '.vue', '.json']
},
devtool: isDevelopment ? 'eval-source-map' : 'source-map'
};
};