webpack+vue开发打包的项目放到服务器上访问不了

我在本地使用vue-cli搭建的项目,tomcat端口号是8080,我自己作了一下把webpack配置的端口号改为8088,目的是为了锻炼自己跨域调接口的能力。本地都ok,都能跑,但是使用npm run build打包后放到服务器上的tomcat下的webapps文件夹下没有作用。
我访问ip:8080显示的是tomcat页面而不是我项目的页面,后面加上项目名就报404,仔细看看本地也是localhost:8088/#/,后面并没有项目名能访问啊,为什么在服务器上不能访问呢?
后来怀疑是不是服务器有问题,因为是我昨天才踩了无数坑搭好的,把老项目放上去完全能跑,说明服务器没问题啊,那么只能是我自己项目的问题了,可是个人真的蛮菜的,始终不知道为什么,只能来社区求助了,谢谢前辈们了!

web.xml配置

<!-- 项目名称 -->

<display-name>degree</display-name>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

</welcome-file-list>

<!-- 配置监听器 -->

<listener>

<listener-class>

org.springframework.web.context.ContextLoaderListener

</listener-class>

</listener>

<listener>

<listener-class>

org.springframework.web.util.IntrospectorCleanupListener

</listener-class>

</listener>

<!-- 配置过滤器,解决POST乱码问题 -->

<filter>

<filter-name>encoding</filter-name>

<filter-class>

org.springframework.web.filter.CharacterEncodingFilter

</filter-class>

<init-param>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>encoding</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<servlet>

<servlet-name>degree</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>

classpath:springmvc-servlet.xml

</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>degree</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

springmvc-servlet.xml:

<!-- 默认的注解映射的支持,自动注册DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter,这个主要是作用于controller -->

<mvc:annotation-driven />

<!-- 启用spring mvc 注解 -->

<context:annotation-config />

<!-- 扫包 -->

<context:component-scan base-package="com.degree.controller.*">

</context:component-scan>

<!-- 对转向页面的路径解析 -->

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />

<property name="prefix" value="" />

<property name="suffix" value="" /> <!-- 可为空 -->

</bean>

webpack配置文件index.js:

const path = require('path')

module.exports = {

dev: {

// Paths

assetsSubDirectory: 'static',

assetsPublicPath: '/',

proxyTable: {

'/degree': {

target: 'http://localhost:8080',

pathRewrite: {'^/': '/'},

changeOrigin: true

}

},

// Various Dev Server settings

host: 'localhost', // can be overwritten by process.env.HOST

port: 8088, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined

autoOpenBrowser: true,

errorOverlay: true,

notifyOnErrors: true,

poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

// Use Eslint Loader?

// If true, your code will be linted during bundling and

// linting errors and warnings will be shown in the console.

useEslint: true,

// If true, eslint errors and warnings will also be shown in the error overlay

// in the browser.

showEslintErrorsInOverlay: false,

/**

* Source Maps

*/

// https://webpack.js.org/configuration/devtool/#development

devtool: 'eval-source-map',

// If you have problems debugging vue-files in devtools,

// set this to false - it *may* help

// https://vue-loader.vuejs.org/en/options.html#cachebusting

cacheBusting: true,

// CSS Sourcemaps off by default because relative paths are "buggy"

// with this option, according to the CSS-Loader README

// (https://github.com/webpack/css-loader#sourcemaps)

// In our experience, they generally work as expected,

// just be aware of this issue when enabling this option.

cssSourceMap: false,

},

build: {

// Template for index.html

index: path.resolve(__dirname, '../dist/index.html'),

// Paths

assetsRoot: path.resolve(__dirname, '../dist'),

assetsSubDirectory: 'static',

assetsPublicPath: '/',

/**

* Source Maps

*/

productionSourceMap: true,

// https://webpack.js.org/configuration/devtool/#production

devtool: '#source-map',

// Gzip off by default as many popular static hosts such as

// Surge or Netlify already gzip all static assets for you.

// Before setting to `true`, make sure to:

// npm install --save-dev compression-webpack-plugin

productionGzip: false,

productionGzipExtensions: ['js', 'css'],

// Run the build command with an extra argument to

// View the bundle analyzer report after build finishes:

// `npm run build --report`

// Set to `true` or `false` to always turn it on or off

bundleAnalyzerReport: process.env.npm_config_report

}

}

图片描述

图片描述

回答:

仔细看了下服务器后台,tomcat正常启动了但是没有加载我的项目,其他项目没有问题,我就草了

以上是 webpack+vue开发打包的项目放到服务器上访问不了 的全部内容, 来源链接: utcz.com/a/167424.html

回到顶部