简体   繁体   English

AngularJS + Gulp文件和文件夹结构以及正确的gulpfule.js配置

[英]AngularJS + Gulp files and folders structure and right gulpfule.js config

I want to create a three page app, i need follow structure: 我想创建一个三页应用程序,我需要遵循以下结构:

frontend
-app
--page1
---page1.js
---page1.html
--page2
---page2.js
---page2.html
--page3
---page3.js
---page3.html
-assets
--style
---main.scss
--js
---main.js
--images
-index.html

public (for production version)

gulpfile.js
package.json

How should i create a tasks for scripts (scripts in different folders) in gulpfile.js? 我应该如何在gulpfile.js中为脚本(不同文件夹中的脚本)创建任务?

Maybe my structure is wrong, then how could it to look like? 也许我的结构是错误的,那么它看起来如何?

Your structure seems right. 您的结构似乎正确。 You can use any architecture you want for your project. 您可以为项目使用所需的任何体系结构。 Regarding Gulp, you just have to know how to filter the javascript source files when you call gulp.src() . 关于Gulp,您只需要知道在调用gulp.src()时如何过滤javascript源文件。 It should be something like this: 应该是这样的:

gulp.task('scripts', function() {
    return gulp.src('./app/**/*.js')
        .pipe() //Do whatever process you need here
        .
        .
        .pipe(gulp.dest('./assets/js/'));
});

A quick recommendation would be to create a gulp.config.js file to handle all the string variables, filters, directories, among others. 一个快速的建议是创建一个gulp.config.js文件来处理所有字符串变量,过滤器,目录等。 Then require it in your gulpfile.js and use those variables to provide a cleaner code. 然后在您的gulpfile.js中要求它,并使用这些变量提供更简洁的代码。 It should be something around this: 应该围绕以下内容:

gulp.config.js (located in the same folder of the gulpfile.js) gulp.config.js(位于gulpfile.js的同一文件夹中)

module.exports = function() {
    var src = './app/';
    var dest = './assets/';

    var config = {
        js: {
            src: src + '**/*.js',
            dest: dest + 'js/'
        }
    };

    return config;
}

gulpfile.js gulpfile.js

var config = require('./gulp.config.js')();

.
.
.

gulp.task('scripts', function() {
    return gulp.src(config.js.src)
        .pipe() //Do whatever process you need here
        .
        .
        .pipe(gulp.dest(config.js.dest));
});

This should work for you. 这应该为您工作。

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

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