{
test: /.js$/,
use: ['babel-loader'],
exclude: /node_modules/
},
{
test: /.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader'] },
{
test: /.(png|jpg|jpeg|gif|eot|ttf|woff|woff2|svg|svgz)(?.+)?$/,
use: [{
loader: 'url-loader',
options: {
limit: 10000
}
}] }
] },
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest'] }),
new HtmlWebpackPlugin({
template: 'src/index.html',
favicon: 'src/logo.png'
})
],
resolve: {
alias: {
'~': resolve(__dirname, 'src')
},
extensions: ['.js', '.vue', '.json', '.css'] },
devServer: {
host: '127.0.0.1',
port: 8010,
proxy: {
'/api/': {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
},
historyApiFallback: {
index: url.parse(options.dev ? '/assets/' : publicPath).pathname
}
},
devtool: options.dev ? '#eval-source-map' : '#source-map'
})
再次打包后,查看index.html,内容如下:
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="utf-8">
<title>系统管理</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="shortcut icon" type="image/x-icon" href="logo.png">
<link rel="shortcut icon" href="/logo.png"></head>
<body>
<div id="app"></div>
<script type="text/javascript" src="/manifest.js?f7d4b2121bc37e262877"></script><script type="text/javascript" src="/vendor.js?9eae337435ee1b63d5cd"></script><script type="text/javascript" src="/index.js?51954197166dd938b54e"></script></body>
</html>
从index.html可以看出已经变成了绝对路径。
2.2 修改Nginx配置
修改nginx.conf配置文件,代码如下:
worker_processes 1;events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
## 指向vue打包后文件位置
root /opt/nginx/dist/;
## 拦截根请求,例如http://localhost
location / {
try_files $uri $uri/ /index.html;
}
## 拦截带有tms-monitor的请求,例如http://localhost/tms-monitor/admin
location ^~/tms-monitor{
if (!-e $request_filename) {
rewrite ^/(.*) /index.html last;










