Last active
August 12, 2024 20:15
-
-
Save sokra/8805639 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Both tabs and spaces are mixed in this sample code.
Could you consider to unify the indentation ?
https://gist.github.com/kitsuyui/5e7524c74b946a09742d/revisions