Browserify angularjs无法加载模块

时间:2014-10-10 08:24:21

标签: angularjs coffeescript browserify

每次我运行gulp文件浏览器并用以下方法咖啡化我的文件时

var gulp = require('gulp');
var browserify = require('gulp-browserify');
var concat = require('gulp-concat');

gulp.task('scripts', function () {
    return gulp.src('app/**/*.coffee', { read: false })
        .pipe(browserify({ transform: ['coffeeify'], extensions: ['.coffee'] }))
        .pipe(concat('bundle.js'))
        .pipe(gulp.dest('./dest/'));
});

gulp.task('default', function () {
    gulp.run('scripts');
});

我的第一行bundle.js上有一个奇怪的错误,我不明白:

Weird bug with browserify

你能帮我解决这个问题吗?我对此错误完全不了解: - /


这是我的app.coffee代码(允许启动应用程序)

require('angular')
require('angular-route')

Application = require('./Application')
application = new Application()
application.start()

这是我的application.coffee类

Route = require('./Route')
Configuration = require('../../config/config')
Routes = require('../../config/route')

class Application

    constructor: ()->
        @name = Configuration.appName
        @dependencies = Configuration.dependencies

    start: ()->
        angular.module @name, @dependencies
        angular.config(@config)

    getName: () ->
        return @name

    getDependencies: ()->
        return @dependencies

    config: ($routeProvider)->
        for r in Routes
            split = r.controller.split(":")
            module = split[0]
            controller = split[1] + 'Controller'
            method = split[2] + 'Action'
            vue = module + '/partials/' + r.view

            @initController(module, controller, method, r.dependencies)
            @handleRouting($routeProvider, vue, controller + '.' + method)

    initController: (module, ctrl, method, dependencies)->
        controller = new (require('../../modules/' + module + '/controller/' + ctrl))
        angular.module(@name, dependencies).controller(eval(controller + '.' + method + '()'))

    handleRouting: (routeProvider, vue, controller) ->
        route = new Route(vue, controller)
        if r.alias
            route.setAlias(r.alias)
        if r.resolve
            route.setResolve(r.resolve)
        routeProvider.when(r.pattern, @handleRouting(vue, controller).getRoute())


module.exports = Application

这是我的路线类

class Route

    constructor: (@template, @controller)->

    getTemplate: ()->
        return @template
    setTemplate: (@template)->

    getController: ()->
        return @controller
    setController: (@controller)->

    getAlias: ()->
        return @alias
    setAlias: (@alias)->

    getResolve: ()->
        return @resolve
    setResolve: (@resole)->

    getRoute: ()->
        route = {}
        route.templateUrl = @template
        route.controller = @controller

        if @alias
            route.controllerAs = @alias
        if @resolve
            route.resolve = @resolve
        return

module.exports = Route

感谢您提前

已编辑:文字中的完整错误 - >

Uncaught Error: Cannot find module 'function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}' 

0 个答案:

没有答案