Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 8, 2019. It is now read-only.
/docsPublic archive
Tobias Koppers edited this pageJan 23, 2014 ·5 revisions

wiki

hot-module-replacement-with-webpack

internal-webpack-plugins

imports-loader and window.jQuery

support for path-to-regexp

moment.js

so i have a couple of things i think should probably be in the docs: 1) best practice for shimming browser js (i.e. a jquery plugin), 2) how to configure for altjs languages, 3) how to configure webpack for browser package managers like bower.

  1. =>http://webpack.github.io/docs/shimming-modules.html
  2. => How to write a loader;http://webpack.github.io/docs/using-loaders.html
  3. => Vendor ModulesSome of them are still work in progressdontkry may be a good start for 3)

Create a enhanced require function

varmyRequire=require("enhanced-require")(module,{// options});// startup your applicationmyRequire("./startup");

Usage

Than you can use them:

// use loadersvarfileContent=require("raw!"+__filename);// use loaders automaticallyvartemplate=require("./my-template.jade");// you need to pass this options:// { module: { loaders: [ { test: /\.jade$/, loader: "jade" } ]}}varhtml=template({content:fileContent});// use require.contextvardirectoryRequire=require.context("raw!./subdir");vartxtFile=directoryRequire("./aFile.txt");// use require.ensurerequire.ensure(["./someFile.js"],function(require){varsomeFile=require("./someFile.js");});// use AMD definerequire.define(["./aDep"],function(aDep){aDep.run();});// use AMD requirerequire(["./bDep"],function(bDep){bDep.doSomething();});

Hot Code Replacement

require("enhanced-require")(module,{hot:true,// enable hot code replacementwatch:true// watch for changes})("./startup");

For hot code reloading you need to follow thehot code reloading spec.

Testing/Mocking

varer=require("enhanced-require");it("should read the config option",function(done){varsubject=er(module,{substitutions:{// specify the exports of a module directly"../lib/config.json":{"test-option":{value:1234}}},substitutionFactories:{// specify lazy generated exports of a module"../lib/otherConfig.json":function(require){// export the same object as "config.json"returnrequire("../lib/config.json");}}})("../lib/subject");varresult=subject.getConfigOption("test-option");should.exist(result);result.should.be.eql({value:1234});});

from commonjs

Differences between CommonJS and RequireJS

There are two main differences between CommonJS and RequireJS.

The first one is how modules are defined.While CommonJS uses its own method (seen above), RequireJS implementsthe AMD (Asynchronous Module Definitions) specification.

The second difference is how dependencies are loaded.While CommonJS expectsrequire calls to behave synchronously,RequireJS loads its modules asynchronously, behaving moreaccordingly as how the browser works.This heavily marks where to use each of these two module systems,CommonJS is used mainly in server JavaScript implementations (Nodejs),while RequireJS is headed to be used in the browser.

webpack 👍

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp