0

安装 famo.us 后,每当我尝试使用默认的 surfaceImage grunt serve 以外的任何内容修改 main.js 文件时,都会抛出一堆 handler.js 错误并且不会加载页面。

我可以添加不同的图像并修改 imageSurface 的大小而不会出现任何问题,但是一旦我尝试添加表面或向现有的 imageSurface 添加属性,就会出现错误。

这也发生在 GitHub 上发布的所有示例中(从示例 main.js 文件运行)。下面的错误是我在修改 main.js 文件时看到的非常典型的错误:

   >> File "app\src\main.js" changed.
Running "jscs:src" (jscs) task
Multiple var declaration at app/src/handler.js :
     6 |var mainContext = Engine.createContext();
     7 |
     8 |var surfaceA, surfaceB;
--------^
     9 |createSurfaces();
    10 |
Illegal trailing whitespace at app/src/handler.js :
    33 |    }
    34 |  });
    35 |
----------^
    36 |  surfaceB = new Surface({
    37 |    size: [100, 100],
Illegal trailing whitespace at app/src/handler.js :
    43 |    }
    44 |  });
    45 |
----------^
    46 |  var modifierB = new StateModifier({
    47 |    origin: [1, 1]
Illegal trailing whitespace at app/src/handler.js :
    47 |    origin: [1, 1]
    48 |  });
    49 |
----------^
    50 |  mainContext.add(surfaceA);
    51 |  mainContext.add(modifierB).add(surfaceB);
Missing line feed at file end at app/src/handler.js :
    50 |  mainContext.add(surfaceA);
    51 |  mainContext.add(modifierB).add(surfaceB);
    52 |}
--------^
>> 5 code style errors found!
Warning: Task "jscs:src" failed. Use --force to continue

.

我对此仍然很陌生,所以我确定我错过了一些非常愚蠢的东西,但不确定是什么。其他人有这样的问题吗?

4

2 回答 2

0

强制它运行或构建的捷径是使用该--force选项。喜欢:

grunt serve --force

或者

grunt --force

只要确保没有非格式问题。

于 2014-06-10T06:40:01.430 回答
0

如果您有兴趣参与开源开发或构建社区插件,您会遇到 Famo.us 希望您遵循的样式指南。

如您所见,样式指南非常挑剔。如果您只想快速启动并运行,您可以简单地禁用强制执行样式的包。这些是 eslint 和 jscs..

进入您的 Gruntfile.js 并注释掉“THIS LINE”或“THESE LINES”下的行集,使其如下所示。

希望这对你有用!

/*global module:false*/

/*Generated initially from grunt-init, heavily inspired by yo webapp*/

module.exports = function(grunt) {
    'use strict';

    // Load grunt tasks automatically
    require('load-grunt-tasks')(grunt);

    // Time how long tasks take. Can help when optimizing build times
    require('time-grunt')(grunt);

    // Project configuration.
    grunt.initConfig({
        // Project settings
        config: {
            // Configurable paths
            app: 'app',
            dist: 'dist'
        },
        // THESE LINES ///////////////
        // eslint: {
        //     options: {
        //         config: '.eslintrc'
        //     },
        //     target: ['<%= config.app %>/src/**/**.js']
        // },
        // THESE LINES ///////////////
        // jscs: {
        //     src: ['<%= config.app %>/src/**/**.js', 'Gruntfile.js'],
        //     options: {
        //         config: '.jscsrc'
        //     }
        // },
        // Watches files for changes and runs tasks based on the changed files
        watch: {
            bower: {
                files: ['bower.json'],
                tasks: ['bower']
            },
            js: {
                files: ['<%= config.app %>/src/**/**.js'],
                // THIS LINE ///////////////
                // tasks: ['jscs', 'eslint'],
                options: {
                    livereload: true
                }
            },
            gruntfile: {
                files: ['Gruntfile.js']
            },
            css: {
                files: ['<%= config.app %>/css/{,*/}*.css'],
                options: {
                    livereload: true
                }
            },
            livereload: {
                options: {
                    livereload: '<%= connect.options.livereload %>'
                },
                files: [
                    '<%= config.app %>/{,*/}*.html',
                    '<%= config.app %>/styles/**/**.css',
                    '<%= config.app %>/images/{,*/}*'
                ]
            }
        },
        // The actual grunt server settings
        connect: {
            options: {
                port: grunt.option('port') || 5555,
                livereload: 35729,
                // Change this to '0.0.0.0' to access the server from outside
                hostname: '0.0.0.0'
            },
            livereload: {
                options: {
                    open: true,
                    base: [
                        '.tmp',
                        '<%= config.app %>'
                    ]
                }
            },
            dist: {
                options: {
                    open: true,
                    base: '<%= config.dist %>',
                    livereload: false
                }
            }
        },

        // Empties folders to start fresh
        clean: {
            dist: {
                files: [{
                    dot: true,
                    src: [
                        '.tmp',
                        '<%= config.dist %>/*',
                        '!<%= config.dist %>/.git*'
                    ]
                }]
            },
            server: '.tmp'
        },

        // Automagically wire-up installed Bower components into your RequireJS config
        bower: {
            raget: {
                rjsConfig: '<%= config.app %>/src/requireConfig.js'
            }
        },

        rev: {
            dist: {
                files: {
                    src: [
                        '<%= config.dist %>/src/{,*/}*.js',
                        '<%= config.dist %>/css/{,*/}*.css',
                        // '<%= config.dist %>/images/{,*/}*.*',
                        '<%= config.dist %>/css/fonts/{,*/}*.*',
                        '<%= config.dist %>/*.{ico,png}'
                    ]
                }
            }
        },

        processhtml: {
            dev: {
                files: {
                    '.tmp/index.html': ['<%= config.app %>/index.html']
                }
            },
            dist: {
                files: {
                    '<%= config.dist %>/index.html': ['<%= config.app %>/index.html']
                }
            },
            options: {
                commentMarker: 'process'
            }
        },

        // Reads HTML for usemin blocks to enable smart builds that automatically
        // concat, uglify and revision files. Creates configurations in memory so
        // additional tasks can operate on them

        useminPrepare: {
            options: {
                dest: '<%= config.dist %>'
            },
            html: '<%= config.dist %>/index.html'
        },

        // Performs reqrite based on rev and the useminPrepare configuration
        usemin: {
            options: {
                assetsDirs: ['<%= config.dist %>', '<%= config.dist %>/images']
            },
            html: ['<%= config.dist %>/{,*/}*.html'],
            css: ['<%= config.dist %>/css/{,*/}*.css']
        },

        htmlmin: {
            dist: {
                options: {
                    collapseBooleanAttributes: true,
                    collapseWhitespace: true,
                    removeAttributeQuotes: true,
                    removeCommentsFromCDATA: true,
                    removeEmptyAttributes: true,
                    removeOptionalTags: true,
                    removeRedundantAttributes: true,
                    useShortDoctype: true
                },
                files: [{
                    expand: true,
                    cwd: '<%= config.dist %>',
                    src: '{,*/}*.html',
                    dest: '<%= config.dist %>'
                }]
            }
        },

        // Copies remaining files to places other tasks can use
        copy: {
            dist: {
                files: [{
                    expand: true,
                    dot: true,
                    cwd: '<%= config.app %>',
                    dest: '<%= config.dist %>',
                    src: [
                        '**/**.{ico,png,txt,jpg}',
                        '.htaccess',
                        'images/{,*/}*.webp',
                        // '{,*/}*.html',
                        'styles/fonts/{,*/}*.*',
                        'lib/famous/**/**.css'
                    ]
                }]
            }
        },
        requirejs: {
            compile: {
                options: {
                    optimize: 'uglify2',
                    uglify2: {
                        mangler: {
                            toplevel: true
                        }
                    },
                    baseUrl: '<%= config.app %>/src',
                    mainConfigFile: '<%= config.app %>/src/requireConfig.js',
                    name: 'almond',
                    include: 'main',
                    insertRequire: ['main'],
                    out: '<%= config.dist %>/src/main.js',
                    wrap: true
                }
            }
        }
    });

    grunt.registerTask('serve', function(target) {
        if (target === 'dist') {
            return grunt.task.run(['build', 'connect:dist:keepalive']);
        }

        grunt.task.run([
            'clean:server',
            // THESE LINES ///////////////
            // 'jscs',
            // 'eslint',
            'processhtml:dev',
            'connect:livereload',
            'watch'
        ]);
    });

    grunt.registerTask('build', [
        'clean:dist',
        // THESE LINES ///////////////
        // 'jscs',
        // 'eslint',
        'processhtml:dist',
        'useminPrepare',
        'requirejs',
        'concat',
        'cssmin',
        'uglify',
        'copy:dist',
        'rev',
        'usemin',
        'htmlmin'
    ]);

    grunt.registerTask('default', [
        'build'
    ]);

};
于 2014-04-30T05:18:06.303 回答