mirror of https://github.com/webpack/webpack.git
Merge branch 'master' into webpack-2
Conflicts: bin/convert-argv.js package.json
This commit is contained in:
commit
ed75627f06
|
@ -1,6 +1,8 @@
|
|||
/node_modules
|
||||
/test/js
|
||||
/test/browsertest/js
|
||||
/benchmark/js
|
||||
/benchmark/fixtures
|
||||
/examples/*/js
|
||||
/coverage
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
env:
|
||||
- NO_WATCH_TESTS=1
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
|
||||
# Contributing
|
||||
|
||||
Most of the time, if webpack is not working correctly for you it is a simple configuration issue.
|
||||
|
||||
If you are still having difficulty after looking over your configuration carefully, please post
|
||||
a question to [StackOverflow with the webpack tag](http://stackoverflow.com/tags/webpack). Questions
|
||||
that include your webpack.config.js and relevant files are more likely to receive responses.
|
||||
|
||||
**If you have discovered a bug or have a feature suggestion, feel free to create an issue on Github.**
|
||||
|
||||
If you have created your own loader/plugin please incude it on the relevant
|
||||
documentation pages:
|
||||
|
||||
[List of loaders](http://webpack.github.io/docs/list-of-loaders.html)
|
||||
[List of plugins](http://webpack.github.io/docs/list-of-plugins.html)
|
||||
|
||||
### Documentation
|
||||
|
||||
webpack is insanely feature rich and documentation is a huge time sink. We
|
||||
greatly appreciate any time spent fixing typos or clarifying sections in the
|
||||
documentation.
|
||||
|
||||
|
||||
## Submitting Changes
|
||||
|
||||
From opening a bug report to creating a pull request: every contribution is
|
||||
appreciated and welcome. If you're planning to implement a new feature or change
|
||||
the api please create an issue first. This way we can ensure that your precious
|
||||
work is not in vain.
|
||||
|
||||
After getting some feedback, push to your fork and submit a pull request. We
|
||||
may suggest some changes or improvements or alternatives, but for small changes
|
||||
your pull request should be accepted quickly.
|
||||
|
||||
Some things that will increase the chance that your pull request is accepted:
|
||||
|
||||
* Write tests
|
||||
* Follow the existing coding style
|
||||
* Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
|
||||
|
128
README.md
128
README.md
|
@ -6,16 +6,23 @@
|
|||
|
||||
# Introduction
|
||||
|
||||
webpack is a bundler for modules. The main purpose is to bundle javascript files for usage in a browser.
|
||||
webpack is a bundler for modules. The main purpose is to bundle javascript
|
||||
files for usage in a browser, yet it is also capable of transforming, bundling,
|
||||
or packaging just about any resource or asset.
|
||||
|
||||
|
||||
**TL;DR**
|
||||
|
||||
* bundles [CommonJs](http://www.commonjs.org/specs/modules/1.0/) and [AMD](https://github.com/amdjs/amdjs-api/wiki/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
|
||||
* Bundles both [CommonJs](http://www.commonjs.org/specs/modules/1.0/) and [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) modules (even combined).
|
||||
* Can create a single bundle or multiple chunks that are asynchronously loaded at runtime (to reduce initial loading time).
|
||||
* Dependencies are resolved during compilation reducing the runtime size.
|
||||
* Loaders can preprocess files while compiling, e.g. coffeescript to javascript, handlebars strings to compiled functions, images to Base64, etc.
|
||||
* Highly modular plugin system to do whatever else your application requires.
|
||||
|
||||
Check the [documentation](http://webpack.github.io/docs/?utm_source=github&utm_medium=readme&utm_campaign=trdr) if you want to know more...
|
||||
# Getting Started
|
||||
|
||||
Check out webpack's [documentation](http://webpack.github.io/docs/?utm_source=github&utm_medium=readme&utm_campaign=trdr) for quick Getting Started guide, in-depth usage,
|
||||
tutorials and resources.
|
||||
|
||||
# Installation
|
||||
|
||||
|
@ -24,39 +31,109 @@ project:
|
|||
|
||||
global:
|
||||
`npm install webpack -g`
|
||||
Usage
|
||||
http://webpack.github.io/docs/tutorials/getting-started/
|
||||
|
||||
# Examples
|
||||
|
||||
Take a look at the [`examples`](https://github.com/webpack/webpack/tree/master/examples) folder.
|
||||
|
||||
|
||||
|
||||
# Features
|
||||
|
||||
## Plugins
|
||||
|
||||
webpack has a [rich plugin interface](http://webpack.github.io/docs/plugins.html). Most of the features within webpack itself use this plugin interface. This makes webpack very **flexible**.
|
||||
webpack has a [rich plugin
|
||||
interface](http://webpack.github.io/docs/plugins.html). Most of the features
|
||||
within webpack itself use this plugin interface. This makes webpack very
|
||||
**flexible**.
|
||||
|
||||
|
||||
## Performance
|
||||
|
||||
webpack uses async I/O and has multiple caching levels. This makes webpack fast and incredibly **fast** on incremental compilations.
|
||||
webpack uses async I/O and has multiple caching levels. This makes webpack fast
|
||||
and incredibly **fast** on incremental compilations.
|
||||
|
||||
## Loaders
|
||||
|
||||
webpack enables use of loaders to preprocess files. This allows you to bundle **any static resource** way beyond javascript. You can easily [write your own loaders](http://webpack.github.io/docs/loaders.html) using node.js.
|
||||
webpack enables use of loaders to preprocess files. This allows you to bundle
|
||||
**any static resource** way beyond javascript. You can easily [write your own
|
||||
loaders](http://webpack.github.io/docs/loaders.html) using node.js.
|
||||
|
||||
## Support
|
||||
Loaders are activated by using `loadername!` prefixes in `require()` statements,
|
||||
or are automatically applied via regex from your webpack configuration.
|
||||
|
||||
webpack supports **AMD and CommonJS** module styles. It performs clever static analysis on the AST of your code. It even has an evaluation engine to evaluate simple expressions. This allows you to **support most existing libraries**.
|
||||
Please see [Using Loaders](http://webpack.github.io/docs/using-loaders.html) for more information.
|
||||
|
||||
**basic**
|
||||
* [`json`](https://github.com/webpack/json-loader): Loads file as JSON
|
||||
* [`raw`](https://github.com/webpack/raw-loader): Loads raw content of a file (as utf-8)
|
||||
* [`val`](https://github.com/webpack/val-loader): Executes code as module and consider exports as JavaScript code
|
||||
* [`script`](https://github.com/webpack/script-loader): Executes a JavaScript file once in global context (like in script tag), requires are not parsed.
|
||||
|
||||
**packaging**
|
||||
* [`file`](https://github.com/webpack/file-loader): Emits the file into the output folder and returns the (relative) url.
|
||||
* [`url`](https://github.com/webpack/url-loader): The url loader works like the file loader, but can return a Data Url if the file is smaller than a limit.
|
||||
* [`image`](https://github.com/tcoopman/image-webpack-loader): Compresses your images. Ideal to use together with `file` or `url`.
|
||||
* [`svgo-loader`](https://github.com/pozadi/svgo-loader): Compresses SVG images using [svgo](https://github.com/svg/svgo) library
|
||||
* [`baggage`](https://github.com/deepsweet/baggage-loader): Automatically require any resources related to the required one
|
||||
* [`polymer-loader`](https://github.com/JonDum/polymer-loader): Process HTML & CSS with preprocessor of choice and `require()` Web Components like first-class modules.
|
||||
|
||||
**dialects**
|
||||
* [`coffee`](https://github.com/webpack/coffee-loader): Loads coffee-script like JavaScript
|
||||
* [`babel`](https://github.com/babel/babel-loader): Turn ES6 code into vanilla ES5 using [Babel](https://github.com/babel/babel).
|
||||
* [`livescript`](https://github.com/appedemic/livescript-loader): Loads LiveScript like JavaScript
|
||||
* [`sweetjs`](https://github.com/jlongster/sweetjs-loader): Use sweetjs macros.
|
||||
* [`traceur`](https://github.com/jupl/traceur-loader): Use future JavaScript features with [Traceur](https://github.com/google/traceur-compiler).
|
||||
* [`typescript`](https://github.com/andreypopp/typescript-loader): Loads TypeScript like JavaScript.
|
||||
|
||||
**templating**
|
||||
* [`html`](https://github.com/webpack/html-loader): Exports HTML as string, require references to static resources.
|
||||
* [`jade`](https://github.com/webpack/jade-loader): Loads jade template and returns a function
|
||||
* [`handlebars`](https://github.com/altano/handlebars-loader): Loads handlebars template and returns a function
|
||||
* [`ractive`](https://github.com/rstacruz/ractive-loader): Pre-compiles Ractive templates for interactive DOM manipulation
|
||||
* [`markdown`](https://github.com/peerigon/markdown-loader): Compiles Markdown to HTML
|
||||
* [`ng-cache`](https://github.com/teux/ng-cache-loader): Puts HTML partials in the Angular's $templateCache
|
||||
|
||||
**styling**
|
||||
* [`style`](https://github.com/webpack/style-loader): Add exports of a module as style to DOM
|
||||
* [`css`](https://github.com/webpack/css-loader): Loads css file with resolved imports and returns css code
|
||||
* [`less`](https://github.com/webpack/less-loader): Loads and compiles a less file
|
||||
* [`sass`](https://github.com/jtangelder/sass-loader): Loads and compiles a scss file
|
||||
* [`stylus`](https://github.com/shama/stylus-loader): Loads and compiles a stylus file
|
||||
|
||||
**misc**
|
||||
* [`po`](https://github.com/dschissler/po-loader): Loads a PO gettext file and returns JSON
|
||||
* [`mocha`](https://github.com/webpack/mocha-loader): Do tests with mocha in browser or node.js
|
||||
* [`eslint`](https://github.com/MoOx/eslint-loader): PreLoader for linting code using ESLint.
|
||||
* [`jshint`](https://github.com/webpack/jshint-loader): PreLoader for linting code.
|
||||
* [`jscs`](https://github.com/unindented/jscs-loader): PreLoader for style checking.
|
||||
* [`injectable`](https://github.com/jauco/webpack-injectable): Allow to inject dependencies into modules
|
||||
* [`transform`](https://github.com/webpack/transform-loader): Use browserify transforms as loader.
|
||||
|
||||
For the full list of loaders, see [list of loaders](http://webpack.github.io/docs/list-of-loaders.html).
|
||||
|
||||
## Module Format (AMD/CommonJS)
|
||||
|
||||
webpack supports **both** AMD and CommonJS module styles. It performs clever static
|
||||
analysis on the AST of your code. It even has an evaluation engine to evaluate
|
||||
simple expressions. This allows you to **support most existing libraries** out of the box.
|
||||
|
||||
## Code Splitting
|
||||
|
||||
webpack allows you to split your codebase into multiple chunks. Chunks are loaded **on demand**. This reduces the initial loading time.
|
||||
webpack allows you to split your codebase into multiple chunks. Chunks are
|
||||
loaded asynchronously at runtime. This reduces the initial loading time.
|
||||
|
||||
[Code Splitting documentation](http://webpack.github.io/docs/code-splitting.html)
|
||||
|
||||
## Optimizations
|
||||
|
||||
webpack can do many optimizations to **reduce the output size**. It also can make your chunks **cache friendly** by using hashes.
|
||||
webpack can do many optimizations to **reduce the output size of your
|
||||
javascript** by deduplicating frequently used modules, minifying, and giving
|
||||
you full control of what is loaded initially and what is loaded at runtime
|
||||
through code splitting. It can also can make your code chunks **cache
|
||||
friendly** by using hashes.
|
||||
|
||||
[Optimization documentation](http://webpack.github.io/docs/optimization.html)
|
||||
|
||||
|
||||
# A small example of what's possible
|
||||
|
@ -120,13 +197,11 @@ function loadTemplateAsync(name, callback) {
|
|||
[documentation](http://webpack.github.io/docs/?utm_source=github&utm_medium=readme&utm_campaign=documentation)
|
||||
|
||||
|
||||
|
||||
## Changelog
|
||||
|
||||
[changelog](http://webpack.github.io/docs/changelog.html)
|
||||
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
You can run the node tests with `npm test`. [](http://travis-ci.org/webpack/webpack) [](https://ci.appveyor.com/project/sokra/webpack/branch/master)
|
||||
|
@ -141,20 +216,27 @@ node build
|
|||
and open `tests.html` in browser.
|
||||
|
||||
|
||||
|
||||
## Contribution
|
||||
|
||||
You are welcome to contribute by opening an issue or a pull request.
|
||||
It would be nice if you open sourced your own loaders or webmodules. :)
|
||||
Most of the time, if webpack is not working correctly for you it is a simple configuration issue.
|
||||
|
||||
You are also welcome to correct any spelling mistakes or any language issues, because my english is not perfect...
|
||||
If you are still having difficulty after looking over your configuration carefully, please post
|
||||
a question to [StackOverflow with the webpack tag](http://stackoverflow.com/tags/webpack). Questions
|
||||
that include your webpack.config.js and relevant files are more likely to receive responses.
|
||||
|
||||
If you want to discuss something or just need help, [here is a gitter.im room](https://gitter.im/webpack/webpack).
|
||||
If you have discovered a bug or have a feature suggestion, feel free to create an issue on Github.
|
||||
|
||||
If you create a loader or plugin, please consider open sourcing it, putting it
|
||||
on NPM and following the `x-loader`, `x-plugin` convention.
|
||||
|
||||
You are also welcome to correct any spelling mistakes or any language issues.
|
||||
|
||||
If you want to discuss something or just need help, [here is our gitter.im room](https://gitter.im/webpack/webpack).
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Copyright (c) 2012-2014 Tobias Koppers
|
||||
Copyright (c) 2012-2015 Tobias Koppers
|
||||
|
||||
MIT (http://www.opensource.org/licenses/mit-license.php)
|
||||
|
||||
|
|
|
@ -0,0 +1,193 @@
|
|||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var Benchmark = require("benchmark");
|
||||
var webpack = require("../");
|
||||
var fixtures = path.join(__dirname, "fixtures");
|
||||
var outputPath = path.join(__dirname, "js");
|
||||
|
||||
var benchmarkOptions = {
|
||||
defer: true,
|
||||
onCycle: function() {
|
||||
process.stderr.write(".");
|
||||
},
|
||||
minSamples: 10
|
||||
};
|
||||
|
||||
function runTimes(compiler, times, deferred) {
|
||||
fs.writeFileSync(path.join(fixtures, "0.js"), "module.exports = " + Math.random(), "utf-8");
|
||||
compiler.run(function(err, stats) {
|
||||
if(err) throw err;
|
||||
if(times === 1)
|
||||
deferred.resolve();
|
||||
else
|
||||
runTimes(compiler, times - 1, deferred);
|
||||
});
|
||||
}
|
||||
|
||||
var tests = {
|
||||
"normal build": [[0, 1, 5, 10, 50, 100, 200], function(size, deferred) {
|
||||
webpack({
|
||||
context: fixtures,
|
||||
entry: "./" + size + ".js",
|
||||
output: {
|
||||
path: outputPath,
|
||||
filename: "bundle.js"
|
||||
}
|
||||
}, function(err, stats) {
|
||||
if(err) throw err;
|
||||
deferred.resolve();
|
||||
});
|
||||
}],
|
||||
"eval dev build": [[0, 1, 2, 5, 10, 15], function(size, deferred) {
|
||||
webpack({
|
||||
context: fixtures,
|
||||
entry: "./" + size + ".big.js",
|
||||
output: {
|
||||
path: outputPath,
|
||||
filename: "bundle.js"
|
||||
},
|
||||
devtool: "eval"
|
||||
}, function(err, stats) {
|
||||
if(err) throw err;
|
||||
deferred.resolve();
|
||||
})
|
||||
}],
|
||||
"sourcemap build": [[0, 1, 2, 5, 10, 15], function(size, deferred) {
|
||||
webpack({
|
||||
context: fixtures,
|
||||
entry: "./" + size + ".big.js",
|
||||
output: {
|
||||
path: outputPath,
|
||||
filename: "bundle.js"
|
||||
},
|
||||
devtool: "source-map"
|
||||
}, function(err, stats) {
|
||||
if(err) throw err;
|
||||
deferred.resolve();
|
||||
})
|
||||
}],
|
||||
"cheap sourcemap build": [[0, 1, 2, 5, 10, 15], function(size, deferred) {
|
||||
webpack({
|
||||
context: fixtures,
|
||||
entry: "./" + size + ".big.js",
|
||||
output: {
|
||||
path: outputPath,
|
||||
filename: "bundle.js"
|
||||
},
|
||||
devtool: "cheap-source-map"
|
||||
}, function(err, stats) {
|
||||
if(err) throw err;
|
||||
deferred.resolve();
|
||||
})
|
||||
}],
|
||||
"build w/ chunks": [[0, 1, 5, 10, 50, 100, 200], function(size, deferred) {
|
||||
webpack({
|
||||
context: fixtures,
|
||||
entry: "./" + size + ".async.js",
|
||||
output: {
|
||||
path: outputPath,
|
||||
filename: "bundle.js"
|
||||
}
|
||||
}, function(err, stats) {
|
||||
if(err) throw err;
|
||||
deferred.resolve();
|
||||
})
|
||||
}],
|
||||
"build w/ chunks": [[0, 1, 5, 10, 50, 100, 200], function(size, deferred) {
|
||||
webpack({
|
||||
context: fixtures,
|
||||
entry: "./" + size + ".async.js",
|
||||
output: {
|
||||
path: outputPath,
|
||||
filename: "bundle.js"
|
||||
}
|
||||
}, function(err, stats) {
|
||||
if(err) throw err;
|
||||
deferred.resolve();
|
||||
})
|
||||
}],
|
||||
"incremental": [[0, 1, 5, 10, 50, 100, 200], function(size, deferred) {
|
||||
var compiler = webpack({
|
||||
cache: true,
|
||||
context: fixtures,
|
||||
entry: "./" + size + ".js",
|
||||
output: {
|
||||
path: outputPath,
|
||||
filename: "bundle.js"
|
||||
}
|
||||
});
|
||||
runTimes(compiler, 2, deferred);
|
||||
}],
|
||||
"incremental cheap sourcemap": [[1, 2, 3, 4, 5, 6], function(size, deferred) {
|
||||
var compiler = webpack({
|
||||
cache: true,
|
||||
context: fixtures,
|
||||
entry: "./200.js",
|
||||
output: {
|
||||
path: outputPath,
|
||||
filename: "bundle.js"
|
||||
},
|
||||
devtool: "cheap-source-map"
|
||||
});
|
||||
runTimes(compiler, size, deferred);
|
||||
}],
|
||||
"incremental2": [[0, 1, 5, 10, 50, 100, 200], function(size, deferred) {
|
||||
var compiler = webpack({
|
||||
cache: true,
|
||||
context: fixtures,
|
||||
entry: "./" + size + ".js",
|
||||
output: {
|
||||
path: outputPath,
|
||||
filename: "bundle.js"
|
||||
}
|
||||
});
|
||||
runTimes(compiler, 3, deferred);
|
||||
}],
|
||||
"incremental4": [[0, 1, 5, 10, 50, 100, 200], function(size, deferred) {
|
||||
var compiler = webpack({
|
||||
cache: true,
|
||||
context: fixtures,
|
||||
entry: "./" + size + ".js",
|
||||
output: {
|
||||
path: outputPath,
|
||||
filename: "bundle.js"
|
||||
}
|
||||
});
|
||||
runTimes(compiler, 5, deferred);
|
||||
}],
|
||||
"incremental16": [[0, 1, 5, 10, 50, 100, 200], function(size, deferred) {
|
||||
var compiler = webpack({
|
||||
cache: true,
|
||||
context: fixtures,
|
||||
entry: "./" + size + ".js",
|
||||
output: {
|
||||
path: outputPath,
|
||||
filename: "bundle.js"
|
||||
}
|
||||
});
|
||||
runTimes(compiler, 17, deferred);
|
||||
}],
|
||||
};
|
||||
|
||||
var suite = new Benchmark.Suite;
|
||||
|
||||
Object.keys(tests).filter(function(name) {
|
||||
if(process.argv.length > 2)
|
||||
return name.indexOf(process.argv[2]) >= 0;
|
||||
return true;
|
||||
}).forEach(function(name) {
|
||||
var test = tests[name];
|
||||
test[0].forEach(function(size) {
|
||||
suite.add(name + " " + size, function(deferred) {
|
||||
test[1](size, deferred);
|
||||
}, benchmarkOptions);
|
||||
});
|
||||
});
|
||||
|
||||
suite.on("cycle", function(event) {
|
||||
process.stderr.write("\n");
|
||||
var b = event.target;
|
||||
console.log(b.name + "\t" + Math.floor(1000 * (b.stats.mean - b.stats.moe)) + "\t" + Math.floor(1000 * (b.stats.mean + b.stats.moe)));
|
||||
});
|
||||
|
||||
suite.run({ async: true });
|
|
@ -0,0 +1,51 @@
|
|||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
||||
var fixtures = path.join(__dirname, "fixtures");
|
||||
|
||||
|
||||
for(var i = 0; i < 1000; i++) {
|
||||
var source = [];
|
||||
if(i > 8)
|
||||
source.push("require("+ JSON.stringify("./" + (i / 8 | 0) + ".js") + ");");
|
||||
if(i > 4)
|
||||
source.push("require("+ JSON.stringify("./" + (i / 4 | 0) + ".js") + ");");
|
||||
if(i > 2)
|
||||
source.push("require("+ JSON.stringify("./" + (i / 2 | 0) + ".js") + ");");
|
||||
if(i > 0)
|
||||
source.push("require("+ JSON.stringify("./" + (i - 1) + ".js") + ");");
|
||||
source.push("module.exports = " + i + ";");
|
||||
fs.writeFileSync(path.join(fixtures, i + ".js"), source.join("\n"), "utf-8");
|
||||
}
|
||||
|
||||
for(var i = 0; i < 1000; i++) {
|
||||
var source = [];
|
||||
source.push("require.ensure([], function(require) {");
|
||||
if(i > 8)
|
||||
source.push("require("+ JSON.stringify("./" + (i / 8 | 0) + ".async.js") + ");");
|
||||
if(i > 4)
|
||||
source.push("require("+ JSON.stringify("./" + (i / 4 | 0) + ".async.js") + ");");
|
||||
if(i > 2)
|
||||
source.push("require("+ JSON.stringify("./" + (i / 2 | 0) + ".async.js") + ");");
|
||||
if(i > 0)
|
||||
source.push("require("+ JSON.stringify("./" + (i - 1) + ".async.js") + ");");
|
||||
source.push("});");
|
||||
source.push("module.exports = " + i + ";");
|
||||
fs.writeFileSync(path.join(fixtures, i + ".async.js"), source.join("\n"), "utf-8");
|
||||
}
|
||||
|
||||
for(var i = 0; i < 100; i++) {
|
||||
var source = [];
|
||||
if(i > 8)
|
||||
source.push("require("+ JSON.stringify("./" + (i / 8 | 0) + ".big.js") + ");");
|
||||
if(i > 4)
|
||||
source.push("require("+ JSON.stringify("./" + (i / 4 | 0) + ".big.js") + ");");
|
||||
if(i > 2)
|
||||
source.push("require("+ JSON.stringify("./" + (i / 2 | 0) + ".big.js") + ");");
|
||||
if(i > 0)
|
||||
source.push("require("+ JSON.stringify("./" + (i - 1) + ".big.js") + ");");
|
||||
for(var j = 0; j < 300; j++)
|
||||
source.push("if(Math.random())hello.world();test.a.b.c.d();x(1,2,3,4);var a,b,c,d,e,f;");
|
||||
source.push("module.exports = " + i + ";");
|
||||
fs.writeFileSync(path.join(fixtures, i + ".big.js"), source.join("\n"), "utf-8");
|
||||
}
|
|
@ -2,6 +2,7 @@ var path = require("path");
|
|||
var fs = require("fs");
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
var resolve = require("enhanced-resolve");
|
||||
var interpret = require('interpret');
|
||||
|
||||
module.exports = function(optimist, argv, convertOptions) {
|
||||
|
||||
|
@ -26,23 +27,42 @@ module.exports = function(optimist, argv, convertOptions) {
|
|||
}
|
||||
|
||||
var configFileLoaded = false;
|
||||
if(argv.config) {
|
||||
options = require(path.resolve(argv.config));
|
||||
configFileLoaded = true;
|
||||
var configPath, ext;
|
||||
if (argv.config) {
|
||||
configPath = path.resolve(argv.config);
|
||||
ext = path.extname(configPath);
|
||||
} else {
|
||||
var configPath = path.resolve("webpack.config.js");
|
||||
if(fs.existsSync(configPath)) {
|
||||
options = require(configPath);
|
||||
configFileLoaded = true;
|
||||
var extensions = Object.keys(interpret.extensions);
|
||||
for(var i = 0; i < extensions.length; i++) {
|
||||
var webpackConfig = path.resolve('webpack.config' + extensions[i]);
|
||||
if(fs.existsSync(webpackConfig)) {
|
||||
ext = extensions[i];
|
||||
configPath = webpackConfig;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(configPath) {
|
||||
var moduleName = interpret.extensions[ext];
|
||||
if (moduleName) {
|
||||
var compiler = require(moduleName);
|
||||
var register = interpret.register[moduleName];
|
||||
var config = interpret.configurations[moduleName];
|
||||
if (register) {
|
||||
register(compiler, config);
|
||||
}
|
||||
}
|
||||
options = require(configPath);
|
||||
configFileLoaded = true;
|
||||
}
|
||||
|
||||
if(typeof options === "function") {
|
||||
options = options(argv.env, argv);
|
||||
}
|
||||
|
||||
if(typeof options !== "object" || options === null) {
|
||||
console.log("Config did not export a object.");
|
||||
console.log("Config did not export an object or a function returning an object.");
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
if(module.hot) {
|
||||
var lastData;
|
||||
var upToDate = function upToDate() {
|
||||
|
@ -8,9 +12,10 @@ if(module.hot) {
|
|||
if(err) {
|
||||
if(module.hot.status() in {abort:1,fail:1}) {
|
||||
console.warn("[HMR] Cannot apply update. Need to do a full reload!");
|
||||
console.warn("[HMR] " + err.stack || err.message);
|
||||
window.location.reload();
|
||||
} else {
|
||||
console.warn("[HMR] Update failed: " + err);
|
||||
console.warn("[HMR] Update failed: " + err.stack || err.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -26,14 +31,8 @@ if(module.hot) {
|
|||
check();
|
||||
}
|
||||
|
||||
if(!updatedModules || updatedModules.length === 0) {
|
||||
console.log("[HMR] Update is empty.");
|
||||
} else {
|
||||
console.log("[HMR] Updated modules:");
|
||||
updatedModules.forEach(function(moduleId) {
|
||||
console.log("[HMR] - " + moduleId);
|
||||
});
|
||||
}
|
||||
require("./log-apply-result")(updatedModules, updatedModules);
|
||||
|
||||
if(upToDate()) {
|
||||
console.log("[HMR] App is up to date.");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
module.exports = function(updatedModules, renewedModules) {
|
||||
var unacceptedModules = updatedModules.filter(function(moduleId) {
|
||||
return renewedModules && renewedModules.indexOf(moduleId) < 0;
|
||||
});
|
||||
|
||||
if(unacceptedModules.length > 0) {
|
||||
console.warn("[HMR] The following modules couldn't be hot updated: (They would need a full reload!)");
|
||||
unacceptedModules.forEach(function(moduleId) {
|
||||
console.warn("[HMR] - " + moduleId);
|
||||
});
|
||||
}
|
||||
|
||||
if(!renewedModules || renewedModules.length === 0) {
|
||||
console.log("[HMR] Nothing hot updated.");
|
||||
} else {
|
||||
console.log("[HMR] Updated modules:");
|
||||
renewedModules.forEach(function(moduleId) {
|
||||
console.log("[HMR] - " + moduleId);
|
||||
});
|
||||
}
|
||||
};
|
|
@ -1,3 +1,7 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
if(module.hot) {
|
||||
var lastData;
|
||||
var upToDate = function upToDate() {
|
||||
|
@ -8,8 +12,9 @@ if(module.hot) {
|
|||
if(err) {
|
||||
if(module.hot.status() in {abort:1,fail:1}) {
|
||||
console.warn("[HMR] Cannot check for update. Need to do a full reload!");
|
||||
console.warn("[HMR] " + err.stack || err.message);
|
||||
} else {
|
||||
console.warn("[HMR] Update check failed: " + err);
|
||||
console.warn("[HMR] Update check failed: " + err.stack || err.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -25,9 +30,10 @@ if(module.hot) {
|
|||
}, function(err, renewedModules) {
|
||||
if(err) {
|
||||
if(module.hot.status() in {abort:1,fail:1}) {
|
||||
console.warn("[HMR] Cannot apply update (Need to do a full reload!): " + err);
|
||||
console.warn("[HMR] Cannot apply update. Need to do a full reload!");
|
||||
console.warn("[HMR] " + err.stack || err.message);
|
||||
} else {
|
||||
console.warn("[HMR] Update failed: " + err);
|
||||
console.warn("[HMR] Update failed: " + err.stack || err.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -36,30 +42,11 @@ if(module.hot) {
|
|||
check();
|
||||
}
|
||||
|
||||
var unacceptedModules = updatedModules.filter(function(moduleId) {
|
||||
return renewedModules.indexOf(moduleId) < 0;
|
||||
});
|
||||
require("./log-apply-result")(updatedModules, renewedModules);
|
||||
|
||||
if(unacceptedModules.length > 0) {
|
||||
console.warn("[HMR] The following modules couldn't be hot updated: (They would need a full reload!)");
|
||||
unacceptedModules.forEach(function(moduleId) {
|
||||
console.warn("[HMR] - " + moduleId);
|
||||
});
|
||||
}
|
||||
|
||||
if(!renewedModules || renewedModules.length === 0) {
|
||||
console.log("[HMR] Nothing hot updated.");
|
||||
} else {
|
||||
console.log("[HMR] Updated modules:");
|
||||
renewedModules.forEach(function(moduleId) {
|
||||
console.log("[HMR] - " + moduleId);
|
||||
});
|
||||
}
|
||||
if(upToDate()) {
|
||||
console.log("[HMR] App is up to date.");
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
29
hot/poll.js
29
hot/poll.js
|
@ -1,13 +1,32 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
if(module.hot) {
|
||||
var hotPollInterval = +(__resourceQuery.substr(1)) || (10*60*1000);
|
||||
setInterval(function() {
|
||||
function checkForUpdate(fromUpdate) {
|
||||
if(module.hot.status() === "idle") {
|
||||
module.hot.check(function(err, updatedModules) {
|
||||
module.hot.check(true, function(err, updatedModules) {
|
||||
if(err) {
|
||||
console.warn("Update failed: " + err);
|
||||
if(module.hot.status() in {abort:1,fail:1}) {
|
||||
console.warn("[HMR] Cannot apply update.");
|
||||
console.warn("[HMR] " + err.stack || err.message);
|
||||
console.warn("[HMR] You need to restart the application!");
|
||||
} else {
|
||||
console.warn("[HMR] Update failed: " + err.stack || err.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(!updatedModules) {
|
||||
if(fromUpdate) console.log("[HMR] Update applied.");
|
||||
return;
|
||||
}
|
||||
require("./log-apply-result")(updatedModules, updatedModules);
|
||||
checkForUpdate(true);
|
||||
});
|
||||
}
|
||||
}, hotPollInterval);
|
||||
}
|
||||
}
|
||||
setInterval(checkForUpdate, hotPollInterval);
|
||||
} else {
|
||||
throw new Error("[HMR] Hot Module Replacement is disabled.");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
if(module.hot) {
|
||||
function checkForUpdate(fromUpdate) {
|
||||
module.hot.check(function(err, updatedModules) {
|
||||
if(err) {
|
||||
if(module.hot.status() in {abort:1,fail:1}) {
|
||||
console.warn("[HMR] Cannot apply update.");
|
||||
console.warn("[HMR] " + err.stack || err.message);
|
||||
console.warn("[HMR] You need to restart the application!");
|
||||
} else {
|
||||
console.warn("[HMR] Update failed: " + err.stack || err.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(!updatedModules) {
|
||||
if(fromUpdate)
|
||||
console.log("[HMR] Update applied.");
|
||||
else
|
||||
console.warn("[HMR] Cannot find update.");
|
||||
return;
|
||||
}
|
||||
|
||||
module.hot.apply({
|
||||
ignoreUnaccepted: true
|
||||
}, function(err, renewedModules) {
|
||||
if(err) {
|
||||
if(module.hot.status() in {abort:1,fail:1}) {
|
||||
console.warn("[HMR] Cannot apply update (Need to do a full reload!)");
|
||||
console.warn("[HMR] " + err.stack || err.message);
|
||||
console.warn("[HMR] You need to restart the application!");
|
||||
} else {
|
||||
console.warn("[HMR] Update failed: " + err.stack || err.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
require("./log-apply-result")(updatedModules, renewedModules);
|
||||
|
||||
checkForUpdate(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
process.on(__resourceQuery.substr(1) || "SIGUSR2", function() {
|
||||
if(module.hot.status() !== "idle") {
|
||||
console.warn("[HMR] Got signal but currently in " + module.hot.status() + " state.");
|
||||
console.warn("[HMR] Need to be in idle state to start hot update.");
|
||||
return;
|
||||
}
|
||||
|
||||
checkForUpdate();
|
||||
});
|
||||
} else {
|
||||
throw new Error("[HMR] Hot Module Replacement is disabled.");
|
||||
}
|
|
@ -45,7 +45,7 @@ BasicEvaluatedExpression.prototype.asBool = function() {
|
|||
else if(this.isRegExp()) return true;
|
||||
else if(this.isArray()) return true;
|
||||
else if(this.isConstArray()) return true;
|
||||
else if(this.isWrapped()) return this.prefix || this.postfix ? true : undefined;
|
||||
else if(this.isWrapped()) return this.prefix && this.prefix.asBool() || this.postfix && this.postfix.asBool() ? true : undefined;
|
||||
return undefined;
|
||||
};
|
||||
BasicEvaluatedExpression.prototype.set = function(value) {
|
||||
|
|
|
@ -36,8 +36,8 @@ CompatibilityPlugin.prototype.apply = function(compiler) {
|
|||
if(last.critical && last.request === "." && last.userRequest === "." && last.recursive)
|
||||
this.state.current.dependencies.pop();
|
||||
}
|
||||
dep.critical = "This seem to be a pre-built javascript file. Even while this is possible, it's not recommended. Try to require to orginal source to get better results.";
|
||||
dep.critical = "This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.";
|
||||
this.state.current.addDependency(dep);
|
||||
return true;
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -18,6 +18,7 @@ var MainTemplate = require("./MainTemplate");
|
|||
var ChunkTemplate = require("./ChunkTemplate");
|
||||
var HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate");
|
||||
var ModuleTemplate = require("./ModuleTemplate");
|
||||
var CachedSource = require("webpack-core/lib/CachedSource");
|
||||
|
||||
function Compilation(compiler) {
|
||||
Tapable.call(this);
|
||||
|
@ -218,7 +219,7 @@ Compilation.prototype.addModuleDependencies = function(module, dependencies, bai
|
|||
return errorOrWarningAndCallback(new ModuleNotFoundError(module, err));
|
||||
}
|
||||
if(!dependantModule) {
|
||||
return callback();
|
||||
return process.nextTick(callback);
|
||||
}
|
||||
if(this.profile) {
|
||||
if(!dependantModule.profile) {
|
||||
|
@ -259,7 +260,7 @@ Compilation.prototype.addModuleDependencies = function(module, dependencies, bai
|
|||
}
|
||||
}
|
||||
|
||||
return callback();
|
||||
return process.nextTick(callback);
|
||||
}
|
||||
|
||||
if(newModule instanceof Module) {
|
||||
|
@ -282,9 +283,9 @@ Compilation.prototype.addModuleDependencies = function(module, dependencies, bai
|
|||
}
|
||||
|
||||
if(recursive) {
|
||||
return this.processModuleDependencies(dependantModule, callback);
|
||||
return process.nextTick(this.processModuleDependencies.bind(this, dependantModule, callback));
|
||||
} else {
|
||||
return callback();
|
||||
return process.nextTick(callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -793,7 +794,7 @@ Compilation.prototype.createChunkAssets = function createChunkAssets() {
|
|||
if(this.cache) {
|
||||
this.cache["c" + chunk.id] = {
|
||||
hash: usedHash,
|
||||
source: source
|
||||
source: source = (source instanceof CachedSource ? source : new CachedSource(source))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,21 +5,29 @@
|
|||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
|
||||
function EvalSourceMapDevToolModuleTemplatePlugin(compilation, sourceMapComment, moduleFilenameTemplate) {
|
||||
function EvalSourceMapDevToolModuleTemplatePlugin(compilation, options, sourceMapComment, moduleFilenameTemplate) {
|
||||
this.compilation = compilation;
|
||||
this.sourceMapComment = sourceMapComment || "//@ sourceMappingURL=[url]";
|
||||
this.moduleFilenameTemplate = moduleFilenameTemplate || "webpack:///[resource-path]?[hash]";
|
||||
this.options = options;
|
||||
}
|
||||
module.exports = EvalSourceMapDevToolModuleTemplatePlugin;
|
||||
|
||||
EvalSourceMapDevToolModuleTemplatePlugin.prototype.apply = function(moduleTemplate) {
|
||||
var self = this;
|
||||
var options = this.options;
|
||||
moduleTemplate.plugin("module", function(source, module, chunk) {
|
||||
if(source.__EvalSourceMapDevTool_Data)
|
||||
return source.__EvalSourceMapDevTool_Data;
|
||||
var content = source.source();
|
||||
|
||||
var sourceMap = source.map();
|
||||
if(source.sourceAndMap) {
|
||||
var sourceAndMap = source.sourceAndMap(options);
|
||||
var sourceMap = sourceAndMap.map;
|
||||
var content = sourceAndMap.source;
|
||||
} else {
|
||||
var sourceMap = source.map(options);
|
||||
var content = source.source();
|
||||
}
|
||||
if(!sourceMap) {
|
||||
return source;
|
||||
}
|
||||
|
|
|
@ -3,18 +3,23 @@
|
|||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var EvalSourceMapDevToolModuleTemplatePlugin = require("./EvalSourceMapDevToolModuleTemplatePlugin");
|
||||
var SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
||||
|
||||
function EvalSourceMapDevToolPlugin(sourceMapComment, moduleFilenameTemplate) {
|
||||
this.sourceMapComment = sourceMapComment;
|
||||
this.moduleFilenameTemplate = moduleFilenameTemplate;
|
||||
function EvalSourceMapDevToolPlugin(options, moduleFilenameTemplate) {
|
||||
if(!options || typeof options !== "object") {
|
||||
this.options = {
|
||||
append: options,
|
||||
moduleFilenameTemplate: moduleFilenameTemplate
|
||||
};
|
||||
} else {
|
||||
this.options = options;
|
||||
}
|
||||
}
|
||||
module.exports = EvalSourceMapDevToolPlugin;
|
||||
EvalSourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
||||
var self = this;
|
||||
var options = this.options;
|
||||
compiler.plugin("compilation", function(compilation) {
|
||||
compilation.plugin("build-module", function(module) {
|
||||
module.useSourceMap = true;
|
||||
});
|
||||
compilation.moduleTemplate.apply(new EvalSourceMapDevToolModuleTemplatePlugin(compilation, self.sourceMapComment, self.moduleFilenameTemplate));
|
||||
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
||||
compilation.moduleTemplate.apply(new EvalSourceMapDevToolModuleTemplatePlugin(compilation, options, options.append, options.moduleFilenameTemplate));
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -394,7 +394,7 @@ var hotInitCode = Template.getFunctionContent(function() {
|
|||
/*foreachInstalledChunks*/ {
|
||||
hotEnsureUpdateChunk(chunkId);
|
||||
}
|
||||
if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
|
||||
if(hotStatus === "prepare" && hotChunksLoading === 0 && hotWaitingFiles === 0) {
|
||||
hotUpdateDownloaded();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -22,7 +22,7 @@ function MainTemplate(outputOptions) {
|
|||
var source = new ConcatSource();
|
||||
source.add("/******/ (function(modules) { // webpackBootstrap\n");
|
||||
source.add(new PrefixSource("/******/", bootstrapSource));
|
||||
source.add("\n/******/ })\n");
|
||||
source.add("/******/ })\n");
|
||||
source.add("/************************************************************************/\n");
|
||||
source.add("/******/ (");
|
||||
var modules = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates, "/******/ ");
|
||||
|
@ -109,7 +109,7 @@ MainTemplate.prototype.render = function(hash, chunk, moduleTemplate, dependency
|
|||
buf.push("");
|
||||
buf.push(this.asString(this.applyPluginsWaterfall("require-extensions", "", chunk, hash)));
|
||||
buf.push(this.asString(this.applyPluginsWaterfall("startup", "", chunk, hash)));
|
||||
var source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t"), "webpack/bootstrap " + hash), chunk, hash, moduleTemplate, dependencyTemplates);
|
||||
var source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t") + "\n", "webpack/bootstrap " + hash), chunk, hash, moduleTemplate, dependencyTemplates);
|
||||
if(chunk.modules.some(function(module) {
|
||||
return (module.id === 0);
|
||||
})) {
|
||||
|
|
|
@ -41,7 +41,13 @@ function getHash(str) {
|
|||
return hash.digest("hex").substr(0, 4);
|
||||
}
|
||||
|
||||
function asRegExp(test) {
|
||||
if(typeof test == "string") test = new RegExp("^"+test.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
|
||||
return test;
|
||||
}
|
||||
|
||||
ModuleFilenameHelpers.createFilename = function createFilename(module, moduleFilenameTemplate, requestShortener) {
|
||||
if(!module) module = "";
|
||||
if(typeof module === "string") {
|
||||
var shortIdentifier = requestShortener.shorten(module);
|
||||
var identifier = shortIdentifier;
|
||||
|
@ -114,3 +120,26 @@ ModuleFilenameHelpers.replaceDuplicates = function replaceDuplicates(array, fn,
|
|||
} else return item;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
ModuleFilenameHelpers.matchPart = function matchPart(str, test) {
|
||||
if(!test) return true;
|
||||
test = asRegExp(test);
|
||||
if(Array.isArray(test)) {
|
||||
return test.map(asRegExp).filter(function(regExp) {
|
||||
return regExp.test(str);
|
||||
}).length > 0;
|
||||
} else {
|
||||
return test.test(str);
|
||||
}
|
||||
};
|
||||
|
||||
ModuleFilenameHelpers.matchObject = function matchObject(obj, str) {
|
||||
if(obj.test)
|
||||
if(!ModuleFilenameHelpers.matchPart(str, obj.test)) return false;
|
||||
if(obj.include)
|
||||
if(!ModuleFilenameHelpers.matchPart(str, obj.include)) return false;
|
||||
if(obj.exclude)
|
||||
if(ModuleFilenameHelpers.matchPart(str, obj.exclude)) return false;
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -8,8 +8,10 @@ var SourceMapSource = require("webpack-core/lib/SourceMapSource");
|
|||
var OriginalSource = require("webpack-core/lib/OriginalSource");
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var ReplaceSource = require("webpack-core/lib/ReplaceSource");
|
||||
var CachedSource = require("webpack-core/lib/CachedSource");
|
||||
var ModuleParseError = require("./ModuleParseError");
|
||||
var TemplateArgumentDependency = require("./dependencies/TemplateArgumentDependency");
|
||||
var AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
|
||||
var path = require("path");
|
||||
|
||||
function NormalModule(request, userRequest, rawRequest, loaders, resource, parser) {
|
||||
|
@ -154,7 +156,7 @@ NormalModule.prototype.source = function(dependencyTemplates, outputOptions, req
|
|||
}
|
||||
}
|
||||
doBlock(this);
|
||||
return source;
|
||||
return new CachedSource(source);
|
||||
};
|
||||
|
||||
NormalModule.prototype.needRebuild = function needRebuild(fileTimestamps, contextTimestamps) {
|
||||
|
@ -212,7 +214,14 @@ NormalModule.prototype.getAllModuleDependencies = function() {
|
|||
return list;
|
||||
};
|
||||
|
||||
NormalModule.prototype.createTemplate = function(keepModules) {
|
||||
NormalModule.prototype.createTemplate = function(keepModules, roots) {
|
||||
roots.sort(function(a, b) {
|
||||
var ia = a.identifier();
|
||||
var ib = b.identifier();
|
||||
if(ia < ib) return -1;
|
||||
if(ib < ia) return 1;
|
||||
return 0;
|
||||
});
|
||||
var template = new NormalModule("", "", "", [], "", null);
|
||||
template._source = this._source;
|
||||
template.built = this.built;
|
||||
|
@ -223,6 +232,13 @@ NormalModule.prototype.createTemplate = function(keepModules) {
|
|||
return m.id;
|
||||
}).join(", ");
|
||||
};
|
||||
template.identifier = function() {
|
||||
var array = roots.map(function(m) {
|
||||
return m.identifier();
|
||||
});
|
||||
array.sort();
|
||||
return array.join("|");
|
||||
};
|
||||
var args = template.arguments = [];
|
||||
function doDeps(deps) {
|
||||
return deps.map(function(dep) {
|
||||
|
|
|
@ -2,9 +2,19 @@
|
|||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var path = require("path");
|
||||
|
||||
function RecordIdsPlugin() {
|
||||
}
|
||||
module.exports = RecordIdsPlugin;
|
||||
|
||||
function makeRelative(compiler, identifier) {
|
||||
var context = compiler.context;
|
||||
return identifier.split("|").map(function(str) {
|
||||
return path.relative(context, str);
|
||||
}).join("|");
|
||||
}
|
||||
|
||||
RecordIdsPlugin.prototype.apply = function(compiler) {
|
||||
compiler.plugin("compilation", function(compilation) {
|
||||
compilation.plugin("record-modules", function(modules, records) {
|
||||
|
@ -12,7 +22,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
|
|||
if(!records.modules) records.modules = {};
|
||||
if(!records.modules.byIdentifier) records.modules.byIdentifier = {};
|
||||
modules.forEach(function(module) {
|
||||
var identifier = module.identifier();
|
||||
var identifier = makeRelative(compiler, module.identifier());
|
||||
records.modules.byIdentifier[identifier] = module.id;
|
||||
});
|
||||
});
|
||||
|
@ -23,7 +33,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
|
|||
var usedIds = {0: true};
|
||||
modules.forEach(function(module) {
|
||||
if(module.id !== null) return;
|
||||
var identifier = module.identifier();
|
||||
var identifier = makeRelative(compiler, module.identifier());
|
||||
var id = records.modules.byIdentifier[identifier];
|
||||
if(id === undefined) return;
|
||||
if(usedIds[id]) return;
|
||||
|
@ -42,7 +52,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
|
|||
block = block.parent;
|
||||
}
|
||||
if(!block.identifier) return null;
|
||||
ident.unshift(block.identifier());
|
||||
ident.unshift(makeRelative(compiler, block.identifier()));
|
||||
return ident.join(":");
|
||||
}
|
||||
compilation.plugin("record-chunks", function(chunks, records) {
|
||||
|
@ -112,4 +122,4 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
|
|||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
var ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
|
||||
function SourceMapDevToolModuleOptionsPlugin(options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
module.exports = SourceMapDevToolModuleOptionsPlugin;
|
||||
|
||||
SourceMapDevToolModuleOptionsPlugin.prototype.apply = function(compilation) {
|
||||
var options = this.options;
|
||||
if(options.module !== false) {
|
||||
compilation.plugin("build-module", function(module) {
|
||||
module.useSourceMap = true;
|
||||
});
|
||||
}
|
||||
if(options.lineToLine === true) {
|
||||
compilation.plugin("build-module", function(module) {
|
||||
module.lineToLine = true;
|
||||
});
|
||||
} else if(options.lineToLine) {
|
||||
compilation.plugin("build-module", function(module) {
|
||||
if(!module.resource) return;
|
||||
var resourcePath = module.resource;
|
||||
var idx = resourcePath.indexOf("?");
|
||||
if(idx >= 0) resourcePath = resourcePath.substr(0, idx);
|
||||
module.lineToLine = ModuleFilenameHelpers.matchObject(options.lineToLine, resourcePath);
|
||||
});
|
||||
}
|
||||
};
|
|
@ -7,8 +7,8 @@ var RequestShortener = require("./RequestShortener");
|
|||
var Template = require("./Template");
|
||||
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var CheapOriginalSource = require("webpack-core/lib/CheapOriginalSource")
|
||||
var ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
var SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
||||
|
||||
function SourceMapDevToolPlugin(options, sourceMappingURLComment, moduleFilenameTemplate, fallbackModuleFilenameTemplate) {
|
||||
if(!options || typeof options !== "object") {
|
||||
|
@ -16,12 +16,13 @@ function SourceMapDevToolPlugin(options, sourceMappingURLComment, moduleFilename
|
|||
this.sourceMappingURLComment = sourceMappingURLComment === false ? false : sourceMappingURLComment || "\n//# sourceMappingURL=[url]";
|
||||
this.moduleFilenameTemplate = moduleFilenameTemplate || "webpack:///[resourcePath]";
|
||||
this.fallbackModuleFilenameTemplate = fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
|
||||
this.options = {};
|
||||
} else {
|
||||
this.sourceMapFilename = options.filename;
|
||||
this.sourceMappingURLComment = options.append === false ? false : options.append || "\n//# sourceMappingURL=[url]";
|
||||
this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resourcePath]";
|
||||
this.fallbackModuleFilenameTemplate = options.fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
|
||||
this.cheapMode = options.cheapMode;
|
||||
this.options = options;
|
||||
}
|
||||
}
|
||||
module.exports = SourceMapDevToolPlugin;
|
||||
|
@ -31,24 +32,16 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
|||
var moduleFilenameTemplate = this.moduleFilenameTemplate;
|
||||
var fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
|
||||
var requestShortener = new RequestShortener(compiler.context);
|
||||
var cheapMode = this.cheapMode;
|
||||
var options = this.options;
|
||||
options.test = options.test || /\.js($|\?)/i;
|
||||
compiler.plugin("compilation", function(compilation) {
|
||||
if(cheapMode) {
|
||||
compilation.moduleTemplate.plugin("module", function(source, module) {
|
||||
var str = source.source();
|
||||
return new CheapOriginalSource(str, module.resource);
|
||||
});
|
||||
} else {
|
||||
compilation.plugin("build-module", function(module) {
|
||||
module.useSourceMap = true;
|
||||
});
|
||||
}
|
||||
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
||||
compilation.plugin("after-optimize-chunk-assets", function(chunks) {
|
||||
var allModules = [];
|
||||
var allModuleFilenames = [];
|
||||
var tasks = [];
|
||||
chunks.forEach(function(chunk) {
|
||||
chunk.files.slice().map(function(file) {
|
||||
chunk.files.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options)).map(function(file) {
|
||||
var asset = this.assets[file];
|
||||
if(asset.__SourceMapDevTool_Data) {
|
||||
var data = asset.__SourceMapDevTool_Data;
|
||||
|
@ -59,12 +52,20 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
|||
}
|
||||
return;
|
||||
}
|
||||
var sourceMap = asset.map();
|
||||
if(asset.sourceAndMap) {
|
||||
var sourceAndMap = asset.sourceAndMap(options);
|
||||
var sourceMap = sourceAndMap.map;
|
||||
var source = sourceAndMap.source;
|
||||
} else {
|
||||
var sourceMap = asset.map(options);
|
||||
var source = asset.source();
|
||||
}
|
||||
if(sourceMap) {
|
||||
return {
|
||||
chunk: chunk,
|
||||
file: file,
|
||||
asset: asset,
|
||||
source: source,
|
||||
sourceMap: sourceMap
|
||||
}
|
||||
}
|
||||
|
@ -90,8 +91,8 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
|||
}, function(ai, bi) {
|
||||
var a = allModules[ai];
|
||||
var b = allModules[bi];
|
||||
a = typeof a === "string" ? a : a.identifier();
|
||||
b = typeof b === "string" ? b : b.identifier();
|
||||
a = !a ? "" : typeof a === "string" ? a : a.identifier();
|
||||
b = !b ? "" : typeof b === "string" ? b : b.identifier();
|
||||
return a.length - b.length;
|
||||
});
|
||||
allModuleFilenames = ModuleFilenameHelpers.replaceDuplicates(allModuleFilenames, function(filename, i, n) {
|
||||
|
@ -108,10 +109,11 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
|||
var file = task.file;
|
||||
var asset = task.asset;
|
||||
var sourceMap = task.sourceMap;
|
||||
var source = task.source;
|
||||
var moduleFilenames = task.moduleFilenames;
|
||||
var modules = task.modules;
|
||||
sourceMap.sources = moduleFilenames;
|
||||
if(sourceMap.sourcesContent && !cheapMode) {
|
||||
if(sourceMap.sourcesContent) {
|
||||
sourceMap.sourcesContent = sourceMap.sourcesContent.map(function(content, i) {
|
||||
return content + "\n\n\n" + ModuleFilenameHelpers.createFooter(modules[i], requestShortener);
|
||||
});
|
||||
|
@ -140,12 +142,12 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
|||
});
|
||||
var sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
|
||||
if(currentSourceMappingURLComment !== false) {
|
||||
asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(asset, currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
|
||||
asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
|
||||
}
|
||||
asset.__SourceMapDevTool_Data[sourceMapFile] = this.assets[sourceMapFile] = new RawSource(JSON.stringify(sourceMap));
|
||||
chunk.files.push(sourceMapFile);
|
||||
} else {
|
||||
asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(asset, currentSourceMappingURLComment
|
||||
asset.__SourceMapDevTool_Data[file] = this.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment
|
||||
.replace(/\[map\]/g, function() {
|
||||
return JSON.stringify(sourceMap);
|
||||
})
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
function WatchIgnorePlugin(paths) {
|
||||
this.paths = paths;
|
||||
}
|
||||
|
||||
module.exports = WatchIgnorePlugin;
|
||||
|
||||
WatchIgnorePlugin.prototype.apply = function (compiler) {
|
||||
compiler.plugin("after-environment", function () {
|
||||
compiler.watchFileSystem = new IgnoringWatchFileSystem(compiler.watchFileSystem, this.paths);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
function IgnoringWatchFileSystem(wfs, paths) {
|
||||
this.wfs = wfs;
|
||||
this.paths = paths;
|
||||
}
|
||||
|
||||
IgnoringWatchFileSystem.prototype.watch = function (files, dirs, missing, startTime, delay, callback, callbackUndelayed) {
|
||||
var ignored = function (path) {
|
||||
return this.paths.some(function (p) {
|
||||
return ((p instanceof RegExp) ? p.test(path) : path.indexOf(p) === 0);
|
||||
});
|
||||
}.bind(this);
|
||||
|
||||
var notIgnored = function (path) { return !ignored(path); };
|
||||
var ignoredFiles = files.filter(ignored);
|
||||
var ignoredDirs = dirs.filter(ignored);
|
||||
|
||||
this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, delay, function (err, filesModified, dirsModified, fileTimestamps, dirTimestamps) {
|
||||
if(err) return callback(err);
|
||||
|
||||
ignoredFiles.forEach(function (path) {
|
||||
fileTimestamps[path] = 1;
|
||||
});
|
||||
|
||||
ignoredDirs.forEach(function (path) {
|
||||
dirTimestamps[path] = 1;
|
||||
});
|
||||
|
||||
callback(err, filesModified, dirsModified, fileTimestamps, dirTimestamps);
|
||||
}, callbackUndelayed);
|
||||
};
|
|
@ -177,48 +177,28 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
|
|||
compiler.apply(new EvalDevToolModulePlugin("//# sourceURL=[url]", options.output.devtoolModuleFilenameTemplate));
|
||||
else if(options.devtool === "#@eval")
|
||||
compiler.apply(new EvalDevToolModulePlugin("//@ sourceURL=[url]\n//# sourceURL=[url]", options.output.devtoolModuleFilenameTemplate));
|
||||
else if(options.devtool === "hidden-sourcemap" || options.devtool === "hidden-source-map")
|
||||
compiler.apply(new SourceMapDevToolPlugin(options.output.sourceMapFilename, false, options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
||||
else if(options.devtool === "sourcemap" || options.devtool === "source-map")
|
||||
compiler.apply(new SourceMapDevToolPlugin(options.output.sourceMapFilename, null, options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
||||
else if(options.devtool === "@sourcemap" || options.devtool === "@source-map")
|
||||
compiler.apply(new SourceMapDevToolPlugin(options.output.sourceMapFilename, "\n/*\n//@ sourceMappingURL=[url]\n*/", options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
||||
else if(options.devtool === "#sourcemap" || options.devtool === "#source-map")
|
||||
compiler.apply(new SourceMapDevToolPlugin(options.output.sourceMapFilename, "\n//# sourceMappingURL=[url]", options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
||||
else if(options.devtool === "#@sourcemap" || options.devtool === "#@source-map")
|
||||
compiler.apply(new SourceMapDevToolPlugin(options.output.sourceMapFilename, "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=[url]\n*/", options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
||||
else if(options.devtool === "inlinesourcemap" ||
|
||||
options.devtool === "inline-sourcemap" ||
|
||||
options.devtool === "inline-source-map")
|
||||
compiler.apply(new SourceMapDevToolPlugin(null, null, options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
||||
else if(options.devtool === "@inlinesourcemap" ||
|
||||
options.devtool === "@inline-sourcemap" ||
|
||||
options.devtool === "@inline-source-map")
|
||||
compiler.apply(new SourceMapDevToolPlugin(null, "\n/*\n//@ sourceMappingURL=[url]\n*/", options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
||||
else if(options.devtool === "#inlinesourcemap" ||
|
||||
options.devtool === "#inline-sourcemap" ||
|
||||
options.devtool === "#inline-source-map")
|
||||
compiler.apply(new SourceMapDevToolPlugin(null, "\n//# sourceMappingURL=[url]", options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
||||
else if(options.devtool === "#@inlinesourcemap" ||
|
||||
options.devtool === "#@inline-sourcemap" ||
|
||||
options.devtool === "#@inline-source-map")
|
||||
compiler.apply(new SourceMapDevToolPlugin(null, "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=[url]\n*/", options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
||||
else if(options.devtool === "evalsourcemap" ||
|
||||
options.devtool === "eval-sourcemap" ||
|
||||
options.devtool === "eval-source-map")
|
||||
compiler.apply(new EvalSourceMapDevToolPlugin(null, options.output.devtoolModuleFilenameTemplate));
|
||||
else if(options.devtool === "@evalsourcemap" ||
|
||||
options.devtool === "@eval-sourcemap" ||
|
||||
options.devtool === "@eval-source-map")
|
||||
compiler.apply(new EvalSourceMapDevToolPlugin("\n/*\n//@ sourceMappingURL=[url]\n*/", options.output.devtoolModuleFilenameTemplate));
|
||||
else if(options.devtool === "#evalsourcemap" ||
|
||||
options.devtool === "#eval-sourcemap" ||
|
||||
options.devtool === "#eval-source-map")
|
||||
compiler.apply(new EvalSourceMapDevToolPlugin("\n//# sourceMappingURL=[url]", options.output.devtoolModuleFilenameTemplate));
|
||||
else if(options.devtool === "#@evalsourcemap" ||
|
||||
options.devtool === "#@eval-sourcemap" ||
|
||||
options.devtool === "#@eval-source-map")
|
||||
compiler.apply(new EvalSourceMapDevToolPlugin("\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=[url]\n*/", options.output.devtoolModuleFilenameTemplate));
|
||||
else if(options.devtool && (options.devtool.indexOf("sourcemap") >= 0 || options.devtool.indexOf("source-map") >= 0)) {
|
||||
var hidden = options.devtool.indexOf("hidden") >= 0;
|
||||
var inline = options.devtool.indexOf("inline") >= 0;
|
||||
var evalWrapped = options.devtool.indexOf("eval") >= 0;
|
||||
var cheap = options.devtool.indexOf("cheap") >= 0;
|
||||
var moduleMaps = options.devtool.indexOf("module") >= 0;
|
||||
var legacy = options.devtool.indexOf("@") >= 0;
|
||||
var modern = options.devtool.indexOf("#") >= 0;
|
||||
var comment = legacy && modern ? "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=[url]\n*/" :
|
||||
legacy ? "\n/*\n//@ sourceMappingURL=[url]\n*/" :
|
||||
modern ? "\n//# sourceMappingURL=[url]" :
|
||||
null;
|
||||
compiler.apply(new (evalWrapped ? EvalSourceMapDevToolPlugin : SourceMapDevToolPlugin)({
|
||||
filename: inline ? null : options.output.sourceMapFilename,
|
||||
moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,
|
||||
fallbackModuleFilenameTemplate: options.output.devtoolFallbackModuleFilenameTemplate,
|
||||
append: hidden ? false : comment,
|
||||
module: moduleMaps ? true : cheap ? false : true,
|
||||
columns: cheap ? false : true,
|
||||
lineToLine: options.output.devtoolLineToLine
|
||||
}));
|
||||
}
|
||||
|
||||
function itemToPlugin(item, name) {
|
||||
if(Array.isArray(item))
|
||||
|
|
|
@ -38,6 +38,7 @@ function WebpackOptionsDefaulter() {
|
|||
this.set("output.hashDigest", "hex");
|
||||
this.set("output.hashDigestLength", 20);
|
||||
this.set("output.sourcePrefix", "\t");
|
||||
this.set("output.devtoolLineToLine", false);
|
||||
|
||||
this.set("node.console", false);
|
||||
this.set("node.process", true);
|
||||
|
|
|
@ -32,8 +32,15 @@ LoaderPlugin.prototype.apply = function(compiler) {
|
|||
|
||||
if(dep.module.error) return callback(dep.module.error);
|
||||
if(!dep.module._source) throw new Error("The module created for a LoaderDependency must have a property _source");
|
||||
var map = dep.module._source.map();
|
||||
var source = dep.module._source.source();
|
||||
var moduleSource = dep.module._source;
|
||||
if(moduleSource.sourceAndMap) {
|
||||
var sourceAndMap = moduleSource.sourceAndMap();
|
||||
var map = sourceAndMap.map;
|
||||
var source = sourceAndMap.source;
|
||||
} else {
|
||||
var map = moduleSource.map();
|
||||
var source = moduleSource.source();
|
||||
}
|
||||
if(dep.module.fileDependencies) {
|
||||
dep.module.fileDependencies.forEach(function(dep) {
|
||||
loaderContext.addDependency(dep);
|
||||
|
@ -50,4 +57,4 @@ LoaderPlugin.prototype.apply = function(compiler) {
|
|||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ DedupePlugin.prototype.apply = function(compiler) {
|
|||
var modulesByHash = {};
|
||||
var allDups = [];
|
||||
modules.forEach(function(module, idx) {
|
||||
if(!module.getSourceHash || !module.getAllModuleDependencies || !module.createTemplate || !module.getTemplateArguments) return;
|
||||
if(!module.getSourceHash || !module.getAllModuleDependencies || !module.createTemplate || !module.getTemplateArguments || module.blocks.length > 0) return;
|
||||
var hash = module.getSourceHash();
|
||||
var dupModule = modulesByHash[hash];
|
||||
if(dupModule) {
|
||||
|
@ -81,7 +81,7 @@ DedupePlugin.prototype.apply = function(compiler) {
|
|||
var commonModules = roots.commonModules;
|
||||
var initialLength = roots.initialCommonModulesLength;
|
||||
if(initialLength !== commonModules.length) {
|
||||
var template = roots[0].createTemplate(commonModules);
|
||||
var template = roots[0].createTemplate(commonModules, roots.slice());
|
||||
roots.template = template;
|
||||
chunk.addModule(template);
|
||||
template.addChunk(chunk);
|
||||
|
@ -185,26 +185,30 @@ DedupePlugin.prototype.apply = function(compiler) {
|
|||
"// Check all modules for deduplicated modules",
|
||||
"for(var i in modules) {",
|
||||
this.indent([
|
||||
"switch(typeof modules[i]) {",
|
||||
"case \"number\":",
|
||||
"if(Object.prototype.hasOwnProperty.call(modules, i)) {",
|
||||
this.indent([
|
||||
"// Module is a copy of another module",
|
||||
"modules[i] = modules[modules[i]];",
|
||||
"break;"
|
||||
]),
|
||||
"case \"object\":",
|
||||
this.indent([
|
||||
"// Module can be created from a template",
|
||||
"modules[i] = (function(_m) {",
|
||||
"switch(typeof modules[i]) {",
|
||||
"case \"number\":",
|
||||
this.indent([
|
||||
"var args = _m.slice(1), fn = modules[_m[0]];",
|
||||
"return function (a,b,c) {",
|
||||
this.indent([
|
||||
"fn.apply(null, [a,b,c].concat(args));"
|
||||
]),
|
||||
"};"
|
||||
"// Module is a copy of another module",
|
||||
"modules[i] = modules[modules[i]];",
|
||||
"break;"
|
||||
]),
|
||||
"}(modules[i]));"
|
||||
"case \"object\":",
|
||||
this.indent([
|
||||
"// Module can be created from a template",
|
||||
"modules[i] = (function(_m) {",
|
||||
this.indent([
|
||||
"var args = _m.slice(1), fn = modules[_m[0]];",
|
||||
"return function (a,b,c) {",
|
||||
this.indent([
|
||||
"fn.apply(null, [a,b,c].concat(args));"
|
||||
]),
|
||||
"};"
|
||||
]),
|
||||
"}(modules[i]));"
|
||||
]),
|
||||
"}"
|
||||
]),
|
||||
"}"
|
||||
]),
|
||||
|
|
|
@ -6,6 +6,7 @@ var SourceMapConsumer = require("webpack-core/lib/source-map").SourceMapConsumer
|
|||
var SourceMapSource = require("webpack-core/lib/SourceMapSource");
|
||||
var RawSource = require("webpack-core/lib/RawSource");
|
||||
var RequestShortener = require("../RequestShortener");
|
||||
var ModuleFilenameHelpers = require("../ModuleFilenameHelpers");
|
||||
var uglify = require("uglify-js");
|
||||
|
||||
function UglifyJsPlugin(options) {
|
||||
|
@ -19,7 +20,6 @@ module.exports = UglifyJsPlugin;
|
|||
|
||||
UglifyJsPlugin.prototype.apply = function(compiler) {
|
||||
var options = this.options;
|
||||
var that = this;
|
||||
options.test = options.test || /\.js($|\?)/i;
|
||||
|
||||
var requestShortener = new RequestShortener(compiler.context);
|
||||
|
@ -40,19 +40,25 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
|
|||
compilation.additionalChunkAssets.forEach(function(file) {
|
||||
files.push(file);
|
||||
});
|
||||
files = files.filter(that.matchObject.bind(that, options));
|
||||
files = files.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options));
|
||||
files.forEach(function(file) {
|
||||
var oldWarnFunction = uglify.AST_Node.warn_function;
|
||||
var warnings = [];
|
||||
try {
|
||||
var asset = compilation.assets[file];
|
||||
var input = asset.source();
|
||||
if(asset.__UglifyJsPlugin) {
|
||||
compilation.assets[file] = asset.__UglifyJsPlugin;
|
||||
return;
|
||||
}
|
||||
if(options.sourceMap !== false) {
|
||||
var inputSourceMap = asset.map();
|
||||
if(asset.sourceAndMap) {
|
||||
var sourceAndMap = asset.sourceAndMap();
|
||||
var inputSourceMap = sourceAndMap.map;
|
||||
var input = sourceAndMap.source;
|
||||
} else {
|
||||
var inputSourceMap = asset.map();
|
||||
var input = asset.source();
|
||||
}
|
||||
var sourceMap = new SourceMapConsumer(inputSourceMap);
|
||||
uglify.AST_Node.warn_function = function(warning) {
|
||||
var match = /\[.+:([0-9]+),([0-9]+)\]/.exec(warning);
|
||||
|
@ -67,6 +73,7 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
|
|||
"[" + requestShortener.shorten(original.source) + ":" + original.line + "," + original.column + "]");
|
||||
};
|
||||
} else {
|
||||
var input = asset.source();
|
||||
uglify.AST_Node.warn_function = function(warning) {
|
||||
warnings.push(warning);
|
||||
};
|
||||
|
@ -102,7 +109,7 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
|
|||
if(map) map = map + "";
|
||||
stream = stream + "";
|
||||
asset.__UglifyJsPlugin = compilation.assets[file] = (map ?
|
||||
new SourceMapSource(stream, file, map, input, inputSourceMap) :
|
||||
new SourceMapSource(stream, file, JSON.parse(map), input, inputSourceMap) :
|
||||
new RawSource(stream));
|
||||
if(warnings.length > 0) {
|
||||
compilation.warnings.push(new Error(file + " from UglifyJs\n" + warnings.join("\n")));
|
||||
|
@ -133,30 +140,3 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
|
|||
});
|
||||
});
|
||||
};
|
||||
|
||||
function asRegExp(test) {
|
||||
if(typeof test == "string") test = new RegExp("^"+test.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
|
||||
return test;
|
||||
}
|
||||
|
||||
UglifyJsPlugin.prototype.matchPart = function matchPart(str, test) {
|
||||
if(!test) return true;
|
||||
test = asRegExp(test);
|
||||
if(Array.isArray(test)) {
|
||||
return test.map(asRegExp).filter(function(regExp) {
|
||||
return regExp.test(str);
|
||||
}).length > 0;
|
||||
} else {
|
||||
return test.test(str);
|
||||
}
|
||||
};
|
||||
|
||||
UglifyJsPlugin.prototype.matchObject = function matchObject(obj, str) {
|
||||
if(obj.test)
|
||||
if(!this.matchPart(str, obj.test)) return false;
|
||||
if(obj.include)
|
||||
if(!this.matchPart(str, obj.include)) return false;
|
||||
if(obj.exclude)
|
||||
if(this.matchPart(str, obj.exclude)) return false;
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -62,6 +62,7 @@ exportPlugins(exports, ".", [
|
|||
"NormalModuleReplacementPlugin",
|
||||
"ContextReplacementPlugin",
|
||||
"IgnorePlugin",
|
||||
"WatchIgnorePlugin",
|
||||
"BannerPlugin",
|
||||
"PrefetchPlugin",
|
||||
"AutomaticPrefetchPlugin",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "webpack",
|
||||
"version": "1.7.2",
|
||||
"version": "1.8.4",
|
||||
"author": "Tobias Koppers @sokra",
|
||||
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.",
|
||||
"dependencies": {
|
||||
|
@ -8,6 +8,7 @@
|
|||
"async": "~0.9.0",
|
||||
"clone": "~0.1.15",
|
||||
"enhanced-resolve": "~0.8.2",
|
||||
"interpret": "^0.5.2",
|
||||
"memory-fs": "~0.2.0",
|
||||
"mkdirp": "~0.5.0",
|
||||
"node-libs-browser": "~0.4.0",
|
||||
|
@ -16,7 +17,7 @@
|
|||
"tapable": "~0.1.8",
|
||||
"uglify-js": "~2.4.13",
|
||||
"watchpack": "^0.2.1",
|
||||
"webpack-core": "~0.5.0"
|
||||
"webpack-core": "~0.6.0"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
|
@ -25,6 +26,7 @@
|
|||
}
|
||||
],
|
||||
"devDependencies": {
|
||||
"benchmark": "^1.0.0",
|
||||
"bundle-loader": "~0.5.0",
|
||||
"coffee-loader": "~0.7.1",
|
||||
"component-webpack-plugin": "~0.2.0",
|
||||
|
@ -36,6 +38,7 @@
|
|||
"jade-loader": "~0.7.0",
|
||||
"json-loader": "~0.5.1",
|
||||
"less-loader": "^2.0.0",
|
||||
"microtime": "^1.2.0",
|
||||
"mocha": "~2.1.0",
|
||||
"raw-loader": "~0.5.0",
|
||||
"script-loader": "~0.6.0",
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
if(process.env.NO_WATCH_TESTS) {
|
||||
describe("NodeWatchFileSystem", function() {
|
||||
it("tests excluded");
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var should = require("should");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
|
|
@ -32,6 +32,9 @@ describe("TestCases", function() {
|
|||
{ name: "devtool-eval-source-map", devtool: "#eval-source-map" },
|
||||
{ name: "devtool-inline-source-map", devtool: "inline-source-map" },
|
||||
{ name: "devtool-source-map", devtool: "#@source-map" },
|
||||
{ name: "devtool-cheap-inline-source-map", devtool: "cheap-inline-source-map" },
|
||||
{ name: "devtool-cheap-eval-source-map", devtool: "cheap-eval-source-map" },
|
||||
{ name: "devtool-cheap-source-map", devtool: "cheap-source-map" },
|
||||
{ name: "minimized", plugins: [
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
sourceMap: false
|
||||
|
|
|
@ -41,7 +41,7 @@ library1.on("exit", function(code) {
|
|||
bindOutput(main);
|
||||
}
|
||||
});
|
||||
// node ../../bin/webpack --output-pathinfo --colors --output-library-target umd --output-jsonp-function webpackJsonpLib2 --output-public-path js/ --output-chunk-file [chunkhash].lib2.js --config library2config.js library2b library2 js/library2.js
|
||||
// node ../../bin/webpack --output-pathinfo --colors --output-library-target umd --output-jsonp-function webpackJsonpLib2 --output-public-path js/ --output-chunk-file [chunkhash].lib2.js --config library2config.coffee library2b library2 js/library2.js
|
||||
var library2 = cp.spawn("node", join(["../../bin/webpack.js", "--output-pathinfo", "--colors", "--output-library-target", "umd", "--output-jsonp-function", "webpackJsonpLib2",
|
||||
"--output-public-path", "js/", "--output-chunk-file", "[chunkhash].lib2.js", "--config", "library2config.js", "library2b", "library2", "js/library2.js"], extraArgsNoWatch));
|
||||
"--output-public-path", "js/", "--output-chunk-file", "[chunkhash].lib2.js", "--config", "library2config.coffee", "library2b", "library2", "js/library2.js"], extraArgsNoWatch));
|
||||
bindOutput(library2);
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
webpack = require("../../");
|
||||
module.exports =
|
||||
output:
|
||||
hashDigestLength: 5
|
||||
module:
|
||||
postLoaders: [
|
||||
{ test: /extra2?\.js/, loader: "raw!extra!val?cacheable" }
|
||||
]
|
||||
amd:
|
||||
fromOptions: true
|
||||
resolve:
|
||||
# cannot resolve should outside the outermost node_modules
|
||||
# so it is injected here
|
||||
alias:
|
||||
should: require.resolve "should"
|
||||
plugins: [
|
||||
new webpack.optimize.LimitChunkCountPlugin 2
|
||||
new webpack.DefinePlugin
|
||||
"typeof CONST_TYPEOF": JSON.stringify("typeof"),
|
||||
CONST_UNDEFINED: undefined,
|
||||
CONST_NULL: null,
|
||||
CONST_TRUE: true,
|
||||
CONST_FALSE: false,
|
||||
CONST_FUNCTION: -> return "ok";
|
||||
CONST_NUMBER: 123,
|
||||
CONST_NUMBER_EXPR: "1*100+23",
|
||||
CONST_OBJECT: {
|
||||
A: 1,
|
||||
B: JSON.stringify("B"),
|
||||
C: -> return "C";
|
||||
}
|
||||
new webpack.ProvidePlugin
|
||||
s3: "submodule3"
|
||||
->
|
||||
this.plugin "normal-module-factory", (nmf) ->
|
||||
nmf.plugin "after-resolve", (data, callback) ->
|
||||
data.resource = data.resource.replace /extra\.js/, "extra2.js";
|
||||
callback null, data;
|
||||
]
|
|
@ -1,48 +0,0 @@
|
|||
var webpack = require("../../");
|
||||
module.exports = {
|
||||
output: {
|
||||
hashDigestLength: 5
|
||||
},
|
||||
module: {
|
||||
postLoaders: [
|
||||
{ test: /extra2?\.js/, loader: "raw!extra!val?cacheable" }
|
||||
]
|
||||
},
|
||||
amd: {
|
||||
fromOptions: true
|
||||
},
|
||||
resolve: {
|
||||
// cannot resolve should outside the outermost node_modules
|
||||
// so it is injected here
|
||||
alias: { should: require.resolve("should") }
|
||||
},
|
||||
plugins: [
|
||||
new webpack.optimize.LimitChunkCountPlugin(2),
|
||||
new webpack.DefinePlugin({
|
||||
"typeof CONST_TYPEOF": JSON.stringify("typeof"),
|
||||
CONST_UNDEFINED: undefined,
|
||||
CONST_NULL: null,
|
||||
CONST_TRUE: true,
|
||||
CONST_FALSE: false,
|
||||
CONST_FUNCTION: function() { return "ok"; },
|
||||
CONST_NUMBER: 123,
|
||||
CONST_NUMBER_EXPR: "1*100+23",
|
||||
CONST_OBJECT: {
|
||||
A: 1,
|
||||
B: JSON.stringify("B"),
|
||||
C: function() { return "C"; }
|
||||
}
|
||||
}),
|
||||
new webpack.ProvidePlugin({
|
||||
s3: "submodule3"
|
||||
}),
|
||||
function() {
|
||||
this.plugin("normal-module-factory", function(nmf) {
|
||||
nmf.plugin("after-resolve", function(data, callback) {
|
||||
data.resource = data.resource.replace(/extra\.js/, "extra2.js");
|
||||
callback(null, data);
|
||||
});
|
||||
});
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
module.exports = "a";
|
|
@ -0,0 +1 @@
|
|||
module.exports = "b";
|
|
@ -0,0 +1,13 @@
|
|||
it("should load a duplicate module with different dependencies correctly", function(done) {
|
||||
var a = require("bundle!./a/file");
|
||||
var b = require("bundle!./b/file");
|
||||
(typeof a).should.be.eql("function");
|
||||
(typeof b).should.be.eql("function");
|
||||
a(function(ra) {
|
||||
ra.should.be.eql("a");
|
||||
b(function(rb) {
|
||||
rb.should.be.eql("b");
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
|
@ -4,6 +4,12 @@ it("should evaluate null", function() {
|
|||
require("fail");
|
||||
});
|
||||
|
||||
if("shouldn't evaluate expression", function() {
|
||||
var value = "";
|
||||
var x = (value + "") ? "fail" : "ok";
|
||||
x.should.be.eql("ok");
|
||||
});
|
||||
|
||||
it("should short-circut evaluating", function() {
|
||||
var expr;
|
||||
var a = false && expr ? require("fail") : require("./a");
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
it("should run", function() {});
|
|
@ -0,0 +1,7 @@
|
|||
var webpack = require("../../../../");
|
||||
|
||||
module.exports = {
|
||||
plugins: [
|
||||
new webpack.WatchIgnorePlugin()
|
||||
]
|
||||
};
|
|
@ -0,0 +1,15 @@
|
|||
it("should include test.js in SourceMap for bundle0 chunk", function() {
|
||||
var fs = require("fs");
|
||||
var source = fs.readFileSync(__filename + ".map", "utf-8");
|
||||
var map = JSON.parse(source);
|
||||
map.sources.should.containEql("webpack:///./test.js");
|
||||
});
|
||||
|
||||
it("should not produce a SourceMap for vendors chunk", function() {
|
||||
var fs = require("fs"),
|
||||
path = require("path"),
|
||||
assert = require("assert");
|
||||
fs.existsSync(path.join(__dirname, "vendors.js.map")).should.be.false;
|
||||
});
|
||||
|
||||
require.include("./test.js");
|
|
@ -0,0 +1,3 @@
|
|||
var foo = {};
|
||||
|
||||
module.exports = foo;
|
|
@ -0,0 +1,3 @@
|
|||
var bar = {};
|
||||
|
||||
module.exports = bar;
|
|
@ -0,0 +1,20 @@
|
|||
var webpack = require("../../../../");
|
||||
module.exports = {
|
||||
node: {
|
||||
__dirname: false,
|
||||
__filename: false
|
||||
},
|
||||
entry: {
|
||||
bundle0: ["./index.js"],
|
||||
vendors: ["./vendors.js"]
|
||||
},
|
||||
output: {
|
||||
filename: "[name].js"
|
||||
},
|
||||
plugins: [
|
||||
new webpack.SourceMapDevToolPlugin({
|
||||
filename: "[file].map",
|
||||
exclude: ["vendors.js"]
|
||||
})
|
||||
]
|
||||
};
|
Loading…
Reference in New Issue