简体   繁体   English

如何在gulp-inject js文件中添加自定义顺序

[英]How to add a custom order in gulp-inject js files

I'm having trouble adding js files in a specific order for my angular project. 我在为角度项目添加特定顺序的js文件时遇到问题。

for eg. 例如。 I have 2 files app.modules.js and app.routes.js 我有2个文件app.modules.jsapp.routes.js

When I use gulp, it loads app.modules.js first. 当我使用app.modules.js ,它首先加载app.modules.js This won't work for me. 这对我不起作用。 I want my app.routes.js to be loaded first. 我希望首先加载我的app.routes.js

I searched for an answer and came up empty. 我找了一个答案然后空了。 Please help. 请帮忙。

Using gulp-inject I think you should do the following: 使用gulp-inject我认为你应该做以下事情:

in the HTML define 2 inject-sections 在HTML中定义2个注入部分

<!-- inject-routes:js -->
<!-- endinject -->
<!-- inject-modules:js -->
<!-- endinject -->

And on the gulpfile.js perform the following: 在gulpfile.js上执行以下操作:

gulp.src('index.html')
.pipe(inject(gulp.src('app.routes.js', {read: false}), {name: 'inject-routes'}))
.pipe(inject(gulp.src('app.modules.js', {read: false}), {name: 'inject-modules'}))
.pipe(gulp.dest('./dist'));

This will put each file in the desired location. 这会将每个文件放在所需的位置。
of course, you can use wildcards to make it work for multiple combinations. 当然,您可以使用通配符使其适用于多种组合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM