项目中遇到需要将vue打包到spring boot 中的static中,直接访问,不需要使用Nginx来访问nginx.具体做法如下:
将vue工程放到spring boot工程最外层
修改pom文件
org.codehaus.mojo
exec-maven-plugin
npm-build-background
verify
exec
${npm.command}
run
prod-package
${basedir}/consumable-background
maven-resources-plugin
3.1.0
copy-consumable-background
prepare-package
copy-resources
${basedir}/target/classes/static/background
${basedir}/consumable-background/dist
配置拦截器(此步可以省略,应为springboot static 路径是默认放开的)
@Override
public void addResourceHandlers(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
}