leftstick / generator-es6-angular

Yeoman generator for es6 based angular skeleton
https://leftstick.github.io/generator-es6-angular
MIT License
74 stars 18 forks source link

部署Tomcat无法获取文件路径 #14

Closed homx closed 7 years ago

homx commented 7 years ago

你好,非常感谢你的这个整合,使用起来非常爽。。。 现在项目完成了,但是发布到Tomcat上的时候页面无法获取到文件路径,请指示。 我在webpack.config.prod.js的输出文件上添加了发布到Tomcat上的项目名称,或者直接和webpack.config.js配置一致,都会读取文件出错。 谢谢!

leftstick commented 7 years ago

首先确认问题是什么:

  1. 是页面干脆打不开,报404?
  2. index.html加载成功,但里面的那两个xxx.bundle.js加载失败404?

如果是第一种

那说明你tomcat就没弄对。我简单说下这个脚手架的部署流程:

  1. 开发
  2. 编译(npm run release) ,注意编译前先把webpack.config.prod.js里的publicPath: '/'改成publicPath: '/你的项目名/'
  3. 然后把build/目录下新生成的所有文件夹拷贝到tomcat/webapps/你的项目名/
  4. 重启tomcat

如果是第二种

那应该就是编译前没有把webpack.config.prod.js改对

homx commented 7 years ago

是第二种。 登录页面加载成功了,get JS文件报错了。 那我该怎么改呢。 output: { path: path.resolve(__dirname, 'build'), filename: '[name].bundle.js', chunkFilename: '[name].bundle.js', publicPath: '/laswim/' }, 我这样改页面是可以加载成功的。 我的项目比如就叫laswim吧。上面的publicPath: '/laswim/'我想是因为加个项目问是没问题的

homx commented 7 years ago

当请求http://localhost:8081/laswim 的时候报Error: [$injector:unpr] Unknown provider: tProvider <- t <- LoginController 当直接请求http://localhost:8081/laswim/login 的时候报404

leftstick commented 7 years ago

先来看这个错:Error: [$injector:unpr] Unknown provider: tProvider <- t <- LoginController

代码错误,出现在依赖注入的部分。因为不确定你用的是什么版本的generator-es6-angular,我需要看下你调用LoginController的代码,以及LoginController自身的代码

第二个问题,直接请求http://localhost:8081/laswim/login 的时候报404,这说明你应该是用了html5 mode,那你还缺两个东西

  1. index.html里的<base href="/">,要改成你的<base href="/laswim/">,看文档html-link-rewriting
  2. tomcat需要做相应的配置,把所有的404重定向到index.html,看这里config-tomcat-html5model
homx commented 7 years ago

你好,请查看leftstick@qq.com邮箱

leftstick commented 7 years ago

你的controller写法缺了依赖注入的部分,如果你参考我之前的例子HomeController,会发现有这么一句话:

/*@ngInject*/
constructor($scope, HomeService) {
        this.$scope = $scope;
        this.HomeService = HomeService;

        this._init_();
        this._destroy_();
}

注意,这里的/*@ngInject*/是关键,看文档ng-annotate

homx commented 7 years ago

非常感谢你,现在可以跑起来了。关于html5 mode我还需要细心看看。再次非常感谢及时回复