Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript RequireJS捆绑包在优化器中失败-“模块共享同一URL” tl;博士_Javascript_Requirejs_Grunt Contrib Requirejs - Fatal编程技术网

Javascript RequireJS捆绑包在优化器中失败-“模块共享同一URL” tl;博士

Javascript RequireJS捆绑包在优化器中失败-“模块共享同一URL” tl;博士,javascript,requirejs,grunt-contrib-requirejs,Javascript,Requirejs,Grunt Contrib Requirejs,RequireJS优化器不喜欢我在模块上定义捆绑包定义,但如果我不定义捆绑包,也找不到模块 长版本 尝试使用requirejs优化器时出现以下错误: Error: Module loading did not complete for: scripts/simulation.bundle, app_mini, testservice The following modules share the same URL. This could be a misconfiguration if t

RequireJS优化器不喜欢我在模块上定义捆绑包定义,但如果我不定义捆绑包,也找不到模块

长版本 尝试使用requirejs优化器时出现以下错误:

Error: Module loading did not complete for: scripts/simulation.bundle, app_mini, testservice
   The following modules share the same URL. This could be a misconfiguration if that URL only has one anonymous module in it:
   .../web/dist/scripts/app.bundle.js: app_mini, testservice
实际上,我正在使用grunt contrib requirejs优化我的js脚本以用于生产。在添加simulator.bundle之前,一切正常

我有3个包:

app.bundle主捆绑包 模拟包 供应商包 这是requirejs grunt任务的模块选项

[{
    name: 'scripts/vendor.bundle',
    exclude: [],
    override: {
      paths: {
        angular: 'bower/angular/angular',
        jquery: 'bower/jquery/dist/jquery',
        ngRoute: "bower/angular-route/angular-route"
      },
      shim: {
        angular: {
          exports: 'angular',
          deps: ['jquery'] // make jquery dependency - angular will replace jquery lite with full jquery
        },
        bundles: {
          'scripts/app.bundle': ['app_mini', 'testservice'],
        },
      }
    }
  },
  {
    name: 'scripts/simulation.bundle',
    exclude: [],
    override: {
      paths: {},
      shim: {},
      bundles: {
        'scripts/vendor.bundle': ['angular', 'jquery'],
        'scripts/app.bundle': ['app_mini', 'testservice']
      }
    }
  },
  {
    name: 'scripts/app.bundle',
    exclude: ['scripts/vendor.bundle'],
    override: {
      paths: {
        app_mini: 'scripts/app.mini',
        testservice: 'scripts/features/test.service'
      },
      shim: {},
      bundles: {
        'scripts/vendor.bundle': ['angular', 'jquery']

      }
    }
  }
]
simulation.bundle中的bundle似乎是问题所在。但是,如果删除它们,则无法找到文件:

>> Error: ENOENT: no such file or directory, open
>> '...\web\dist\app_mini.js'
>> In module tree:
>>     scripts/simulation.bundle
simulation.bundle只是一个虚拟模块,加载角度和应用程序:


因此,无论哪种方式,优化器都无法处理依赖关系。我必须如何配置它才能使其工作?

好的,我再次发布了我自己问题的答案,我希望其他人能从我的错误中获益

所以我发现:

Bundle配置仅适用于requireJS,不适用于优化器

我在配置中定义的捆绑包导致模块共享相同url的错误

正确的方法是为所有模块定义所有路径,并通过名称明确排除不应包含在模块中的模块

例如,app_mini应该放在app.bundle中,但因为它是simulation.bundle中所必需的,所以它会包含在那里,因为排除app.bundle还不可能,此时它还没有优化,所以我们需要直接排除app_mini

因此,一个工作配置将如下所示:未测试

paths: {
    angular: 'bower/angular/angular',
    jquery: 'bower/jquery/dist/jquery',
    ngRoute: "bower/angular-route/angular-route"
    app_mini: 'scripts/app.mini',
    testservice: 'scripts/features/test.service'
},
shim: {
    angular: {
        exports: 'angular',
        deps: ['jquery'] // make jquery dependency - angular will replace jquery lite with full jquery
    }
},

modules: [
    {
        name: 'scripts/vendor.bundle',
        exclude: [],
    },
    {
        name: 'scripts/simulation.bundle',
        exclude: [`app_mini`],
    },
    {
        name: 'scripts/app.bundle',
        exclude: ['scripts/vendor.bundle'],
    }
}]
paths: {
    angular: 'bower/angular/angular',
    jquery: 'bower/jquery/dist/jquery',
    ngRoute: "bower/angular-route/angular-route"
    app_mini: 'scripts/app.mini',
    testservice: 'scripts/features/test.service'
},
shim: {
    angular: {
        exports: 'angular',
        deps: ['jquery'] // make jquery dependency - angular will replace jquery lite with full jquery
    }
},

modules: [
    {
        name: 'scripts/vendor.bundle',
        exclude: [],
    },
    {
        name: 'scripts/simulation.bundle',
        exclude: [`app_mini`],
    },
    {
        name: 'scripts/app.bundle',
        exclude: ['scripts/vendor.bundle'],
    }
}]