Closed homx closed 7 years ago
首先确认问题是什么:
404
?index.html
加载成功,但里面的那两个xxx.bundle.js
加载失败404
?如果是第一种
那说明你tomcat
就没弄对。我简单说下这个脚手架的部署流程:
npm run release
) ,注意编译前先把webpack.config.prod.js
里的publicPath: '/'
改成publicPath: '/你的项目名/'
build/
目录下新生成的所有文件夹拷贝到tomcat/webapps/你的项目名/
下tomcat
如果是第二种
那应该就是编译前没有把webpack.config.prod.js
改对
是第二种。
登录页面加载成功了,get JS文件报错了。
那我该怎么改呢。
output: { path: path.resolve(__dirname, 'build'), filename: '[name].bundle.js', chunkFilename: '[name].bundle.js', publicPath: '/laswim/' },
我这样改页面是可以加载成功的。
我的项目比如就叫laswim吧。上面的publicPath: '/laswim/'我想是因为加个项目问是没问题的
当请求http://localhost:8081/laswim 的时候报Error: [$injector:unpr] Unknown provider: tProvider <- t <- LoginController
当直接请求http://localhost:8081/laswim/login 的时候报404
先来看这个错:Error: [$injector:unpr] Unknown provider: tProvider <- t <- LoginController
:
代码错误,出现在依赖注入的部分。因为不确定你用的是什么版本的generator-es6-angular
,我需要看下你调用LoginController
的代码,以及LoginController
自身的代码
第二个问题,直接请求http://localhost:8081/laswim/login 的时候报404
,这说明你应该是用了html5 mode
,那你还缺两个东西
index.html
里的<base href="/">
,要改成你的<base href="/laswim/">
,看文档html-link-rewritingtomcat
需要做相应的配置,把所有的404
重定向到index.html
,看这里config-tomcat-html5model你好,请查看leftstick@qq.com邮箱
你的controller
写法缺了依赖注入的部分,如果你参考我之前的例子HomeController,会发现有这么一句话:
/*@ngInject*/
constructor($scope, HomeService) {
this.$scope = $scope;
this.HomeService = HomeService;
this._init_();
this._destroy_();
}
注意,这里的
/*@ngInject*/
是关键,看文档ng-annotate
非常感谢你,现在可以跑起来了。关于html5 mode我还需要细心看看。再次非常感谢及时回复
你好,非常感谢你的这个整合,使用起来非常爽。。。 现在项目完成了,但是发布到Tomcat上的时候页面无法获取到文件路径,请指示。 我在webpack.config.prod.js的输出文件上添加了发布到Tomcat上的项目名称,或者直接和webpack.config.js配置一致,都会读取文件出错。 谢谢!