Skip to content

Instantly share code, notes, and snippets.

@sokra
Last active November 21, 2025 19:18
Show Gist options
  • Select an option

  • Save sokra/8805639 to your computer and use it in GitHub Desktop.

Select an option

Save sokra/8805639 to your computer and use it in GitHub Desktop.

Revisions

  1. sokra revised this gist Dec 30, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions webpack.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    // webpack is a module bundler
    // This means webpack takes modules with dependencies
    // and emit static assets representing that modules.
    // and emits static assets representing those modules.

    // dependencies can be written in CommonJs
    var commonjs = require("./commonjs");
    @@ -32,8 +32,8 @@ require("./cup");

    function loadTemplate(name) {
    return require("./templates/" + name + ".jade");
    // many expression are supported in require calls
    // a clever parser extract information and concludes
    // 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.
  2. sokra revised this gist Feb 5, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion webpack.js
    Original file line number Diff line number Diff line change
    @@ -42,7 +42,8 @@ function loadTemplate(name) {

    // ... and you can combine everything
    function loadTemplateAsync(name, callback) {
    require(["bundle?lazy!./templates/" + name + ".jade"], function(templateBundle) {
    require(["bundle?lazy!./templates/" + name + ".jade"],
    function(templateBundle) {
    templateBundle(callback);
    });
    }
  3. sokra revised this gist Feb 4, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion webpack.js
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ require("./cup");


    function loadTemplate(name) {
    return require("./templates/" + name ".jade");
    return require("./templates/" + name + ".jade");
    // many expression are supported in require calls
    // a clever parser extract information and concludes
    // that everything in "./templates" that matches
  4. sokra created this gist Feb 4, 2014.
    48 changes: 48 additions & 0 deletions webpack.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    // webpack is a module bundler
    // This means webpack takes modules with dependencies
    // and emit static assets representing that 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 expression are supported in require calls
    // a clever parser extract 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);
    });
    }