nikospara/require-lazy

语言: JavaScript

git: https://github.com/nikospara/require-lazy

一个RequireJS插件,用于延迟加载与r.js一起打包的AMD模块,自动拆分打包的代码,...
A RequireJS plugin for lazy loading AMD modules packaged with r.js, automatically splitting packaged code in bundles,…
README.md (中文)

需要懒惰

一个RequireJS插件,用于延迟加载与r.js一起打包的AMD模块,自动拆分打包 捆绑包中的代码,仅在代码更改时缓存捆绑包,以及定义模块元数据 和Javascript应用程序中的模块发现。

快速示例

主模块(main.js):

define(["lazy!modules/m1", "lazy!modules/m2", "lazy!text!templates/faq.html"],
function(m1, m2, faq) {
    ...
});

在最简单的情况下,模块main,m1,m2没有共同的依赖关系,Require-Lazy 构建脚本将创建4个单独的包。一个将包含main.js和lazy.js,一个m1.js 及其所有依赖项,一个m2.js及其所有依赖项和一个text.js和faq.html。

每个模块的URL如下所示:

/scripts/app/m1-built.js?v=684beaf379a164c2d4044a74f22ffc6d

v request参数是构建文件内容的哈希值,用作缓存破坏程序。

懒惰的插件将用惰性存根替换每个惰性模块。存根(当时) 一个方法,get()返回真实模块的promise:

m1.get().done(function(m) {
    // here m is the real module
});

可以在examples / simple中找到更详细的讨论和示例项目设置 目录。

依赖

该项目需要,包含或使用以下代码:

  • Node.js(构建目标应用程序并运行示例所必需的)
  • requirejs
  • 杏仁
  • lazyload
  • r.js
  • node.extend
  • jQuery(依赖于Deferred实现,可以通过适配器使用任何其他库;请参阅此测试以获取示例)
  • expressjs(用于提供示例)

发展现状

这个项目正在开发中。虽然很多事情都有效,但预计会有所改善 还有更多人不会。更糟糕的是,有些东西可能无法按预期工作。而且代码是 尚未经过彻底测试。

但是,我对目前的工作方式非常满意;我不希望任何激进的API /用法更改。 这意味着该项目可以被认为是相当稳定的API /使用方式。

欢迎提出想法,批评,评论和代码贡献!

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

require-lazy

A RequireJS plugin for lazy loading AMD modules packaged with r.js, automatically splitting packaged
code in bundles, cache-breaking the bundles only when the code changes, and defining module metadata
and module discovery in Javascript applications.

Quick Example

Main module (main.js):

define(["lazy!modules/m1", "lazy!modules/m2", "lazy!text!templates/faq.html"],
function(m1, m2, faq) {
    ...
});

In the simplest case where the modules main, m1, m2 have no common dependencies, Require-Lazy
build scripts will create 4 separate bundles. One will contain main.js and lazy.js, one m1.js
and all its dependencies, one m2.js and all its dependencies and one text.js and faq.html.

The URL for each module will look like:

/scripts/app/m1-built.js?v=684beaf379a164c2d4044a74f22ffc6d

The v request parameter is a hash of the contents of the built file, used as cache-breaker.

The lazy plugin will replace each lazy module with a lazy stub. The stub has (for the time)
one method, get() that returns a promise for the real module:

m1.get().done(function(m) {
    // here m is the real module
});

A more detailed discussion and an example project setup can be found in the examples/simple
directory.

Dependencies

This project requires, includes, or uses code from:

Development Status

This project is an idea under development. While many things work, it is expected
that many more will not. Even worse, some things may not work as expected. Moreover the code is
not thoroughly tested yet.

However, I am quite satisfied with how things work at the moment; I do not expect any radical API/usage changes.
This means that this project can be considered fairly stable API/usage-wise.

Ideas, criticism, comments, code contributions are all welcome!