Webpack 介绍
webpack 是一个模块打包器,主要目的是在浏览器上打包 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 @R_698_4045@ion 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); }); }
Webpack 官网
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。