Webpack 是一个模块绑定器,主要目的是在浏览器上绑定 JavaScript 文件。
特性:
bundles CommonJs and AMD modules. (even combined)
can create a single bundle or multiple chunks loaded on demand, to reduce iNitial loading time.
dependencIEs are resolved during comPILation reducing the runtime size
loaders can preprocess files while compiling, i. e. coffee-script to javascript
示例代码:
// webpack is a module bundler // This means webpack takes modules with dependencies // and emits static assets representing those modules. // dependencies can be written in CommonJs var commonjs = require("./commonjs"); // or in AMD define(["amd-module", "../file"], Function(amdModule, file) { // while previous constructs are sync // this is async require(["big-module/big/file"], function(big) { // for async dependencies webpack splits // your application into multiple "chunks". // This part of your application is // loaded on demand (CODE Splitting) var stuff = require("../my/stuff"); // "../my/stuff" is also loaded on demand // because it's in the callback function // of the AMD require }); }); require("coffee!./cup.coffee"); // "Loaders" can be used to preprocess files. // They can be prefixed in the require call // or configured in the configuRATion. require("./cup"); // This does the same when you add ".coffee" to the extensions // and configure the "coffee" loader for /\.coffee$/ function loadTemplate(name) { return require("./templates/" + name + ".JADE"); // many Expressions are supported in require calls // a clever parser exTracts information and concludes // that everyThing in "./templates" that matches // /\.jade$/ should be included in the bundle, as it // can be required. } // ... and you can combine everything function loadTemplateAsync(name, callback) { require(["bundle?lazy!./templates/" + name + ".jade"], function(templateBundle) { templateBundle(callback); }); }
发布于 2018-01-25 03:27:29 | 218 次阅读
发布于 2017-09-17 00:02:57 | 123 次阅读
发布于 2017-08-01 00:17:19 | 175 次阅读
发布于 2017-05-10 02:48:41 | 113 次阅读
发布于 2017-04-05 00:29:06 | 181 次阅读
发布于 2017-02-03 00:31:12 | 132 次阅读
发布于 2017-01-18 07:00:25 | 130 次阅读
发布于 2017-01-17 01:22:38 | 130 次阅读
发布于 2016-12-30 23:49:10 | 103 次阅读
发布于 2016-11-16 02:52:36 | 133 次阅读
发布于 2016-11-16 00:19:02 | 175 次阅读