我对requirejs 2.0感到困惑。在使用!order标记之前,但现在javascript不能按顺序加载(除非我运行optimize)。显然,orderjs支持已删除

如果我有5个脚本,并且我需要按顺序加载前三个脚本,我将如何在shim中使用它?

在我做之前

require([
    "order!libraries/file1",
    "order!libraries/file2",
    "order!includes/file3",
    "libraries/file4",
    "libraries/file5"
],
function(){
console.log("All done. Everything loaded. Now we can start the app");
});


我现在如何将其翻译为requirejs 2?

最佳答案

require.config({
  paths: {
    file1: 'libraries/file1',
    file2: 'libraries/file2',
    file3: 'libraries/file3',
    file4: 'libraries/file4',
    file5: 'libraries/file5'
  },
  shim: {
    'file2': ['file1'],
    'file3': ['file2']
  }
});

require([
    "file1",
    "file2",
    "file3",
    "file4",
    "file5"
],
function(){
  console.log("All done. Everything loaded. Now we can start the app");
});

关于javascript - requirejs按顺序加载东西,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12785930/

10-14 06:49