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
|
/node_modules
|
||||||
/test/js
|
/test/js
|
||||||
/test/browsertest/js
|
/test/browsertest/js
|
||||||
|
/benchmark/js
|
||||||
|
/benchmark/fixtures
|
||||||
/examples/*/js
|
/examples/*/js
|
||||||
/coverage
|
/coverage
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
sudo: false
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "0.10"
|
- "0.10"
|
||||||
- "0.12"
|
- "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
|
# 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**
|
**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)
|
* 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 loaded on demand, to reduce initial loading time.
|
* 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
|
* Dependencies are resolved during compilation reducing the runtime size.
|
||||||
* loaders can preprocess files while compiling, i. e. coffee-script to javascript
|
* 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
|
# Installation
|
||||||
|
|
||||||
|
@ -24,39 +31,109 @@ project:
|
||||||
|
|
||||||
global:
|
global:
|
||||||
`npm install webpack -g`
|
`npm install webpack -g`
|
||||||
|
Usage
|
||||||
|
http://webpack.github.io/docs/tutorials/getting-started/
|
||||||
|
|
||||||
# Examples
|
# Examples
|
||||||
|
|
||||||
Take a look at the [`examples`](https://github.com/webpack/webpack/tree/master/examples) folder.
|
Take a look at the [`examples`](https://github.com/webpack/webpack/tree/master/examples) folder.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
|
|
||||||
## Plugins
|
## 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
|
## 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
|
## 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
|
## 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
|
## 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
|
# 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)
|
[documentation](http://webpack.github.io/docs/?utm_source=github&utm_medium=readme&utm_campaign=documentation)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
[changelog](http://webpack.github.io/docs/changelog.html)
|
[changelog](http://webpack.github.io/docs/changelog.html)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Tests
|
## 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)
|
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.
|
and open `tests.html` in browser.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
|
|
||||||
You are welcome to contribute by opening an issue or a pull request.
|
Most of the time, if webpack is not working correctly for you it is a simple configuration issue.
|
||||||
It would be nice if you open sourced your own loaders or webmodules. :)
|
|
||||||
|
|
||||||
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
|
## License
|
||||||
|
|
||||||
Copyright (c) 2012-2014 Tobias Koppers
|
Copyright (c) 2012-2015 Tobias Koppers
|
||||||
|
|
||||||
MIT (http://www.opensource.org/licenses/mit-license.php)
|
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");
|
var fs = require("fs");
|
||||||
fs.existsSync = fs.existsSync || path.existsSync;
|
fs.existsSync = fs.existsSync || path.existsSync;
|
||||||
var resolve = require("enhanced-resolve");
|
var resolve = require("enhanced-resolve");
|
||||||
|
var interpret = require('interpret');
|
||||||
|
|
||||||
module.exports = function(optimist, argv, convertOptions) {
|
module.exports = function(optimist, argv, convertOptions) {
|
||||||
|
|
||||||
|
@ -26,23 +27,42 @@ module.exports = function(optimist, argv, convertOptions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var configFileLoaded = false;
|
var configFileLoaded = false;
|
||||||
if(argv.config) {
|
var configPath, ext;
|
||||||
options = require(path.resolve(argv.config));
|
if (argv.config) {
|
||||||
configFileLoaded = true;
|
configPath = path.resolve(argv.config);
|
||||||
|
ext = path.extname(configPath);
|
||||||
} else {
|
} else {
|
||||||
var configPath = path.resolve("webpack.config.js");
|
var extensions = Object.keys(interpret.extensions);
|
||||||
if(fs.existsSync(configPath)) {
|
for(var i = 0; i < extensions.length; i++) {
|
||||||
options = require(configPath);
|
var webpackConfig = path.resolve('webpack.config' + extensions[i]);
|
||||||
configFileLoaded = true;
|
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") {
|
if(typeof options === "function") {
|
||||||
options = options(argv.env, argv);
|
options = options(argv.env, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof options !== "object" || options === null) {
|
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);
|
process.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
/*
|
||||||
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||||
|
Author Tobias Koppers @sokra
|
||||||
|
*/
|
||||||
if(module.hot) {
|
if(module.hot) {
|
||||||
var lastData;
|
var lastData;
|
||||||
var upToDate = function upToDate() {
|
var upToDate = function upToDate() {
|
||||||
|
@ -8,9 +12,10 @@ if(module.hot) {
|
||||||
if(err) {
|
if(err) {
|
||||||
if(module.hot.status() in {abort:1,fail:1}) {
|
if(module.hot.status() in {abort:1,fail:1}) {
|
||||||
console.warn("[HMR] Cannot apply update. Need to do a full reload!");
|
console.warn("[HMR] Cannot apply update. Need to do a full reload!");
|
||||||
|
console.warn("[HMR] " + err.stack || err.message);
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
} else {
|
} else {
|
||||||
console.warn("[HMR] Update failed: " + err);
|
console.warn("[HMR] Update failed: " + err.stack || err.message);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -26,14 +31,8 @@ if(module.hot) {
|
||||||
check();
|
check();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!updatedModules || updatedModules.length === 0) {
|
require("./log-apply-result")(updatedModules, updatedModules);
|
||||||
console.log("[HMR] Update is empty.");
|
|
||||||
} else {
|
|
||||||
console.log("[HMR] Updated modules:");
|
|
||||||
updatedModules.forEach(function(moduleId) {
|
|
||||||
console.log("[HMR] - " + moduleId);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if(upToDate()) {
|
if(upToDate()) {
|
||||||
console.log("[HMR] App is up to date.");
|
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) {
|
if(module.hot) {
|
||||||
var lastData;
|
var lastData;
|
||||||
var upToDate = function upToDate() {
|
var upToDate = function upToDate() {
|
||||||
|
@ -8,8 +12,9 @@ if(module.hot) {
|
||||||
if(err) {
|
if(err) {
|
||||||
if(module.hot.status() in {abort:1,fail:1}) {
|
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] Cannot check for update. Need to do a full reload!");
|
||||||
|
console.warn("[HMR] " + err.stack || err.message);
|
||||||
} else {
|
} else {
|
||||||
console.warn("[HMR] Update check failed: " + err);
|
console.warn("[HMR] Update check failed: " + err.stack || err.message);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -25,9 +30,10 @@ if(module.hot) {
|
||||||
}, function(err, renewedModules) {
|
}, function(err, renewedModules) {
|
||||||
if(err) {
|
if(err) {
|
||||||
if(module.hot.status() in {abort:1,fail:1}) {
|
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 {
|
} else {
|
||||||
console.warn("[HMR] Update failed: " + err);
|
console.warn("[HMR] Update failed: " + err.stack || err.message);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -36,30 +42,11 @@ if(module.hot) {
|
||||||
check();
|
check();
|
||||||
}
|
}
|
||||||
|
|
||||||
var unacceptedModules = updatedModules.filter(function(moduleId) {
|
require("./log-apply-result")(updatedModules, renewedModules);
|
||||||
return 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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if(upToDate()) {
|
if(upToDate()) {
|
||||||
console.log("[HMR] App is up to date.");
|
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) {
|
if(module.hot) {
|
||||||
var hotPollInterval = +(__resourceQuery.substr(1)) || (10*60*1000);
|
var hotPollInterval = +(__resourceQuery.substr(1)) || (10*60*1000);
|
||||||
setInterval(function() {
|
function checkForUpdate(fromUpdate) {
|
||||||
if(module.hot.status() === "idle") {
|
if(module.hot.status() === "idle") {
|
||||||
module.hot.check(function(err, updatedModules) {
|
module.hot.check(true, function(err, updatedModules) {
|
||||||
if(err) {
|
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;
|
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.isRegExp()) return true;
|
||||||
else if(this.isArray()) return true;
|
else if(this.isArray()) return true;
|
||||||
else if(this.isConstArray()) 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;
|
return undefined;
|
||||||
};
|
};
|
||||||
BasicEvaluatedExpression.prototype.set = function(value) {
|
BasicEvaluatedExpression.prototype.set = function(value) {
|
||||||
|
|
|
@ -36,8 +36,8 @@ CompatibilityPlugin.prototype.apply = function(compiler) {
|
||||||
if(last.critical && last.request === "." && last.userRequest === "." && last.recursive)
|
if(last.critical && last.request === "." && last.userRequest === "." && last.recursive)
|
||||||
this.state.current.dependencies.pop();
|
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);
|
this.state.current.addDependency(dep);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,7 @@ var MainTemplate = require("./MainTemplate");
|
||||||
var ChunkTemplate = require("./ChunkTemplate");
|
var ChunkTemplate = require("./ChunkTemplate");
|
||||||
var HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate");
|
var HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate");
|
||||||
var ModuleTemplate = require("./ModuleTemplate");
|
var ModuleTemplate = require("./ModuleTemplate");
|
||||||
|
var CachedSource = require("webpack-core/lib/CachedSource");
|
||||||
|
|
||||||
function Compilation(compiler) {
|
function Compilation(compiler) {
|
||||||
Tapable.call(this);
|
Tapable.call(this);
|
||||||
|
@ -218,7 +219,7 @@ Compilation.prototype.addModuleDependencies = function(module, dependencies, bai
|
||||||
return errorOrWarningAndCallback(new ModuleNotFoundError(module, err));
|
return errorOrWarningAndCallback(new ModuleNotFoundError(module, err));
|
||||||
}
|
}
|
||||||
if(!dependantModule) {
|
if(!dependantModule) {
|
||||||
return callback();
|
return process.nextTick(callback);
|
||||||
}
|
}
|
||||||
if(this.profile) {
|
if(this.profile) {
|
||||||
if(!dependantModule.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) {
|
if(newModule instanceof Module) {
|
||||||
|
@ -282,9 +283,9 @@ Compilation.prototype.addModuleDependencies = function(module, dependencies, bai
|
||||||
}
|
}
|
||||||
|
|
||||||
if(recursive) {
|
if(recursive) {
|
||||||
return this.processModuleDependencies(dependantModule, callback);
|
return process.nextTick(this.processModuleDependencies.bind(this, dependantModule, callback));
|
||||||
} else {
|
} else {
|
||||||
return callback();
|
return process.nextTick(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -793,7 +794,7 @@ Compilation.prototype.createChunkAssets = function createChunkAssets() {
|
||||||
if(this.cache) {
|
if(this.cache) {
|
||||||
this.cache["c" + chunk.id] = {
|
this.cache["c" + chunk.id] = {
|
||||||
hash: usedHash,
|
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 RawSource = require("webpack-core/lib/RawSource");
|
||||||
var ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
var ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||||
|
|
||||||
function EvalSourceMapDevToolModuleTemplatePlugin(compilation, sourceMapComment, moduleFilenameTemplate) {
|
function EvalSourceMapDevToolModuleTemplatePlugin(compilation, options, sourceMapComment, moduleFilenameTemplate) {
|
||||||
this.compilation = compilation;
|
this.compilation = compilation;
|
||||||
this.sourceMapComment = sourceMapComment || "//@ sourceMappingURL=[url]";
|
this.sourceMapComment = sourceMapComment || "//@ sourceMappingURL=[url]";
|
||||||
this.moduleFilenameTemplate = moduleFilenameTemplate || "webpack:///[resource-path]?[hash]";
|
this.moduleFilenameTemplate = moduleFilenameTemplate || "webpack:///[resource-path]?[hash]";
|
||||||
|
this.options = options;
|
||||||
}
|
}
|
||||||
module.exports = EvalSourceMapDevToolModuleTemplatePlugin;
|
module.exports = EvalSourceMapDevToolModuleTemplatePlugin;
|
||||||
|
|
||||||
EvalSourceMapDevToolModuleTemplatePlugin.prototype.apply = function(moduleTemplate) {
|
EvalSourceMapDevToolModuleTemplatePlugin.prototype.apply = function(moduleTemplate) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var options = this.options;
|
||||||
moduleTemplate.plugin("module", function(source, module, chunk) {
|
moduleTemplate.plugin("module", function(source, module, chunk) {
|
||||||
if(source.__EvalSourceMapDevTool_Data)
|
if(source.__EvalSourceMapDevTool_Data)
|
||||||
return 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) {
|
if(!sourceMap) {
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,23 @@
|
||||||
Author Tobias Koppers @sokra
|
Author Tobias Koppers @sokra
|
||||||
*/
|
*/
|
||||||
var EvalSourceMapDevToolModuleTemplatePlugin = require("./EvalSourceMapDevToolModuleTemplatePlugin");
|
var EvalSourceMapDevToolModuleTemplatePlugin = require("./EvalSourceMapDevToolModuleTemplatePlugin");
|
||||||
|
var SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
||||||
|
|
||||||
function EvalSourceMapDevToolPlugin(sourceMapComment, moduleFilenameTemplate) {
|
function EvalSourceMapDevToolPlugin(options, moduleFilenameTemplate) {
|
||||||
this.sourceMapComment = sourceMapComment;
|
if(!options || typeof options !== "object") {
|
||||||
this.moduleFilenameTemplate = moduleFilenameTemplate;
|
this.options = {
|
||||||
|
append: options,
|
||||||
|
moduleFilenameTemplate: moduleFilenameTemplate
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
module.exports = EvalSourceMapDevToolPlugin;
|
module.exports = EvalSourceMapDevToolPlugin;
|
||||||
EvalSourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
EvalSourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
||||||
var self = this;
|
var options = this.options;
|
||||||
compiler.plugin("compilation", function(compilation) {
|
compiler.plugin("compilation", function(compilation) {
|
||||||
compilation.plugin("build-module", function(module) {
|
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
||||||
module.useSourceMap = true;
|
compilation.moduleTemplate.apply(new EvalSourceMapDevToolModuleTemplatePlugin(compilation, options, options.append, options.moduleFilenameTemplate));
|
||||||
});
|
|
||||||
compilation.moduleTemplate.apply(new EvalSourceMapDevToolModuleTemplatePlugin(compilation, self.sourceMapComment, self.moduleFilenameTemplate));
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -394,7 +394,7 @@ var hotInitCode = Template.getFunctionContent(function() {
|
||||||
/*foreachInstalledChunks*/ {
|
/*foreachInstalledChunks*/ {
|
||||||
hotEnsureUpdateChunk(chunkId);
|
hotEnsureUpdateChunk(chunkId);
|
||||||
}
|
}
|
||||||
if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
|
if(hotStatus === "prepare" && hotChunksLoading === 0 && hotWaitingFiles === 0) {
|
||||||
hotUpdateDownloaded();
|
hotUpdateDownloaded();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,7 +22,7 @@ function MainTemplate(outputOptions) {
|
||||||
var source = new ConcatSource();
|
var source = new ConcatSource();
|
||||||
source.add("/******/ (function(modules) { // webpackBootstrap\n");
|
source.add("/******/ (function(modules) { // webpackBootstrap\n");
|
||||||
source.add(new PrefixSource("/******/", bootstrapSource));
|
source.add(new PrefixSource("/******/", bootstrapSource));
|
||||||
source.add("\n/******/ })\n");
|
source.add("/******/ })\n");
|
||||||
source.add("/************************************************************************/\n");
|
source.add("/************************************************************************/\n");
|
||||||
source.add("/******/ (");
|
source.add("/******/ (");
|
||||||
var modules = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates, "/******/ ");
|
var modules = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates, "/******/ ");
|
||||||
|
@ -109,7 +109,7 @@ MainTemplate.prototype.render = function(hash, chunk, moduleTemplate, dependency
|
||||||
buf.push("");
|
buf.push("");
|
||||||
buf.push(this.asString(this.applyPluginsWaterfall("require-extensions", "", chunk, hash)));
|
buf.push(this.asString(this.applyPluginsWaterfall("require-extensions", "", chunk, hash)));
|
||||||
buf.push(this.asString(this.applyPluginsWaterfall("startup", "", 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) {
|
if(chunk.modules.some(function(module) {
|
||||||
return (module.id === 0);
|
return (module.id === 0);
|
||||||
})) {
|
})) {
|
||||||
|
|
|
@ -41,7 +41,13 @@ function getHash(str) {
|
||||||
return hash.digest("hex").substr(0, 4);
|
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) {
|
ModuleFilenameHelpers.createFilename = function createFilename(module, moduleFilenameTemplate, requestShortener) {
|
||||||
|
if(!module) module = "";
|
||||||
if(typeof module === "string") {
|
if(typeof module === "string") {
|
||||||
var shortIdentifier = requestShortener.shorten(module);
|
var shortIdentifier = requestShortener.shorten(module);
|
||||||
var identifier = shortIdentifier;
|
var identifier = shortIdentifier;
|
||||||
|
@ -114,3 +120,26 @@ ModuleFilenameHelpers.replaceDuplicates = function replaceDuplicates(array, fn,
|
||||||
} else return item;
|
} 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 OriginalSource = require("webpack-core/lib/OriginalSource");
|
||||||
var RawSource = require("webpack-core/lib/RawSource");
|
var RawSource = require("webpack-core/lib/RawSource");
|
||||||
var ReplaceSource = require("webpack-core/lib/ReplaceSource");
|
var ReplaceSource = require("webpack-core/lib/ReplaceSource");
|
||||||
|
var CachedSource = require("webpack-core/lib/CachedSource");
|
||||||
var ModuleParseError = require("./ModuleParseError");
|
var ModuleParseError = require("./ModuleParseError");
|
||||||
var TemplateArgumentDependency = require("./dependencies/TemplateArgumentDependency");
|
var TemplateArgumentDependency = require("./dependencies/TemplateArgumentDependency");
|
||||||
|
var AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
|
|
||||||
function NormalModule(request, userRequest, rawRequest, loaders, resource, parser) {
|
function NormalModule(request, userRequest, rawRequest, loaders, resource, parser) {
|
||||||
|
@ -154,7 +156,7 @@ NormalModule.prototype.source = function(dependencyTemplates, outputOptions, req
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
doBlock(this);
|
doBlock(this);
|
||||||
return source;
|
return new CachedSource(source);
|
||||||
};
|
};
|
||||||
|
|
||||||
NormalModule.prototype.needRebuild = function needRebuild(fileTimestamps, contextTimestamps) {
|
NormalModule.prototype.needRebuild = function needRebuild(fileTimestamps, contextTimestamps) {
|
||||||
|
@ -212,7 +214,14 @@ NormalModule.prototype.getAllModuleDependencies = function() {
|
||||||
return list;
|
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);
|
var template = new NormalModule("", "", "", [], "", null);
|
||||||
template._source = this._source;
|
template._source = this._source;
|
||||||
template.built = this.built;
|
template.built = this.built;
|
||||||
|
@ -223,6 +232,13 @@ NormalModule.prototype.createTemplate = function(keepModules) {
|
||||||
return m.id;
|
return m.id;
|
||||||
}).join(", ");
|
}).join(", ");
|
||||||
};
|
};
|
||||||
|
template.identifier = function() {
|
||||||
|
var array = roots.map(function(m) {
|
||||||
|
return m.identifier();
|
||||||
|
});
|
||||||
|
array.sort();
|
||||||
|
return array.join("|");
|
||||||
|
};
|
||||||
var args = template.arguments = [];
|
var args = template.arguments = [];
|
||||||
function doDeps(deps) {
|
function doDeps(deps) {
|
||||||
return deps.map(function(dep) {
|
return deps.map(function(dep) {
|
||||||
|
|
|
@ -2,9 +2,19 @@
|
||||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||||
Author Tobias Koppers @sokra
|
Author Tobias Koppers @sokra
|
||||||
*/
|
*/
|
||||||
|
var path = require("path");
|
||||||
|
|
||||||
function RecordIdsPlugin() {
|
function RecordIdsPlugin() {
|
||||||
}
|
}
|
||||||
module.exports = 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) {
|
RecordIdsPlugin.prototype.apply = function(compiler) {
|
||||||
compiler.plugin("compilation", function(compilation) {
|
compiler.plugin("compilation", function(compilation) {
|
||||||
compilation.plugin("record-modules", function(modules, records) {
|
compilation.plugin("record-modules", function(modules, records) {
|
||||||
|
@ -12,7 +22,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
|
||||||
if(!records.modules) records.modules = {};
|
if(!records.modules) records.modules = {};
|
||||||
if(!records.modules.byIdentifier) records.modules.byIdentifier = {};
|
if(!records.modules.byIdentifier) records.modules.byIdentifier = {};
|
||||||
modules.forEach(function(module) {
|
modules.forEach(function(module) {
|
||||||
var identifier = module.identifier();
|
var identifier = makeRelative(compiler, module.identifier());
|
||||||
records.modules.byIdentifier[identifier] = module.id;
|
records.modules.byIdentifier[identifier] = module.id;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -23,7 +33,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
|
||||||
var usedIds = {0: true};
|
var usedIds = {0: true};
|
||||||
modules.forEach(function(module) {
|
modules.forEach(function(module) {
|
||||||
if(module.id !== null) return;
|
if(module.id !== null) return;
|
||||||
var identifier = module.identifier();
|
var identifier = makeRelative(compiler, module.identifier());
|
||||||
var id = records.modules.byIdentifier[identifier];
|
var id = records.modules.byIdentifier[identifier];
|
||||||
if(id === undefined) return;
|
if(id === undefined) return;
|
||||||
if(usedIds[id]) return;
|
if(usedIds[id]) return;
|
||||||
|
@ -42,7 +52,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
|
||||||
block = block.parent;
|
block = block.parent;
|
||||||
}
|
}
|
||||||
if(!block.identifier) return null;
|
if(!block.identifier) return null;
|
||||||
ident.unshift(block.identifier());
|
ident.unshift(makeRelative(compiler, block.identifier()));
|
||||||
return ident.join(":");
|
return ident.join(":");
|
||||||
}
|
}
|
||||||
compilation.plugin("record-chunks", function(chunks, records) {
|
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 Template = require("./Template");
|
||||||
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
||||||
var RawSource = require("webpack-core/lib/RawSource");
|
var RawSource = require("webpack-core/lib/RawSource");
|
||||||
var CheapOriginalSource = require("webpack-core/lib/CheapOriginalSource")
|
|
||||||
var ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
var ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||||
|
var SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
||||||
|
|
||||||
function SourceMapDevToolPlugin(options, sourceMappingURLComment, moduleFilenameTemplate, fallbackModuleFilenameTemplate) {
|
function SourceMapDevToolPlugin(options, sourceMappingURLComment, moduleFilenameTemplate, fallbackModuleFilenameTemplate) {
|
||||||
if(!options || typeof options !== "object") {
|
if(!options || typeof options !== "object") {
|
||||||
|
@ -16,12 +16,13 @@ function SourceMapDevToolPlugin(options, sourceMappingURLComment, moduleFilename
|
||||||
this.sourceMappingURLComment = sourceMappingURLComment === false ? false : sourceMappingURLComment || "\n//# sourceMappingURL=[url]";
|
this.sourceMappingURLComment = sourceMappingURLComment === false ? false : sourceMappingURLComment || "\n//# sourceMappingURL=[url]";
|
||||||
this.moduleFilenameTemplate = moduleFilenameTemplate || "webpack:///[resourcePath]";
|
this.moduleFilenameTemplate = moduleFilenameTemplate || "webpack:///[resourcePath]";
|
||||||
this.fallbackModuleFilenameTemplate = fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
|
this.fallbackModuleFilenameTemplate = fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
|
||||||
|
this.options = {};
|
||||||
} else {
|
} else {
|
||||||
this.sourceMapFilename = options.filename;
|
this.sourceMapFilename = options.filename;
|
||||||
this.sourceMappingURLComment = options.append === false ? false : options.append || "\n//# sourceMappingURL=[url]";
|
this.sourceMappingURLComment = options.append === false ? false : options.append || "\n//# sourceMappingURL=[url]";
|
||||||
this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resourcePath]";
|
this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resourcePath]";
|
||||||
this.fallbackModuleFilenameTemplate = options.fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
|
this.fallbackModuleFilenameTemplate = options.fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
|
||||||
this.cheapMode = options.cheapMode;
|
this.options = options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = SourceMapDevToolPlugin;
|
module.exports = SourceMapDevToolPlugin;
|
||||||
|
@ -31,24 +32,16 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
||||||
var moduleFilenameTemplate = this.moduleFilenameTemplate;
|
var moduleFilenameTemplate = this.moduleFilenameTemplate;
|
||||||
var fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
|
var fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
|
||||||
var requestShortener = new RequestShortener(compiler.context);
|
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) {
|
compiler.plugin("compilation", function(compilation) {
|
||||||
if(cheapMode) {
|
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
compilation.plugin("after-optimize-chunk-assets", function(chunks) {
|
compilation.plugin("after-optimize-chunk-assets", function(chunks) {
|
||||||
var allModules = [];
|
var allModules = [];
|
||||||
var allModuleFilenames = [];
|
var allModuleFilenames = [];
|
||||||
var tasks = [];
|
var tasks = [];
|
||||||
chunks.forEach(function(chunk) {
|
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];
|
var asset = this.assets[file];
|
||||||
if(asset.__SourceMapDevTool_Data) {
|
if(asset.__SourceMapDevTool_Data) {
|
||||||
var data = asset.__SourceMapDevTool_Data;
|
var data = asset.__SourceMapDevTool_Data;
|
||||||
|
@ -59,12 +52,20 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
||||||
}
|
}
|
||||||
return;
|
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) {
|
if(sourceMap) {
|
||||||
return {
|
return {
|
||||||
chunk: chunk,
|
chunk: chunk,
|
||||||
file: file,
|
file: file,
|
||||||
asset: asset,
|
asset: asset,
|
||||||
|
source: source,
|
||||||
sourceMap: sourceMap
|
sourceMap: sourceMap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,8 +91,8 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
||||||
}, function(ai, bi) {
|
}, function(ai, bi) {
|
||||||
var a = allModules[ai];
|
var a = allModules[ai];
|
||||||
var b = allModules[bi];
|
var b = allModules[bi];
|
||||||
a = typeof a === "string" ? a : a.identifier();
|
a = !a ? "" : typeof a === "string" ? a : a.identifier();
|
||||||
b = typeof b === "string" ? b : b.identifier();
|
b = !b ? "" : typeof b === "string" ? b : b.identifier();
|
||||||
return a.length - b.length;
|
return a.length - b.length;
|
||||||
});
|
});
|
||||||
allModuleFilenames = ModuleFilenameHelpers.replaceDuplicates(allModuleFilenames, function(filename, i, n) {
|
allModuleFilenames = ModuleFilenameHelpers.replaceDuplicates(allModuleFilenames, function(filename, i, n) {
|
||||||
|
@ -108,10 +109,11 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
|
||||||
var file = task.file;
|
var file = task.file;
|
||||||
var asset = task.asset;
|
var asset = task.asset;
|
||||||
var sourceMap = task.sourceMap;
|
var sourceMap = task.sourceMap;
|
||||||
|
var source = task.source;
|
||||||
var moduleFilenames = task.moduleFilenames;
|
var moduleFilenames = task.moduleFilenames;
|
||||||
var modules = task.modules;
|
var modules = task.modules;
|
||||||
sourceMap.sources = moduleFilenames;
|
sourceMap.sources = moduleFilenames;
|
||||||
if(sourceMap.sourcesContent && !cheapMode) {
|
if(sourceMap.sourcesContent) {
|
||||||
sourceMap.sourcesContent = sourceMap.sourcesContent.map(function(content, i) {
|
sourceMap.sourcesContent = sourceMap.sourcesContent.map(function(content, i) {
|
||||||
return content + "\n\n\n" + ModuleFilenameHelpers.createFooter(modules[i], requestShortener);
|
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, "/");
|
var sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
|
||||||
if(currentSourceMappingURLComment !== false) {
|
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));
|
asset.__SourceMapDevTool_Data[sourceMapFile] = this.assets[sourceMapFile] = new RawSource(JSON.stringify(sourceMap));
|
||||||
chunk.files.push(sourceMapFile);
|
chunk.files.push(sourceMapFile);
|
||||||
} else {
|
} 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() {
|
.replace(/\[map\]/g, function() {
|
||||||
return JSON.stringify(sourceMap);
|
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));
|
compiler.apply(new EvalDevToolModulePlugin("//# sourceURL=[url]", options.output.devtoolModuleFilenameTemplate));
|
||||||
else if(options.devtool === "#@eval")
|
else if(options.devtool === "#@eval")
|
||||||
compiler.apply(new EvalDevToolModulePlugin("//@ sourceURL=[url]\n//# sourceURL=[url]", options.output.devtoolModuleFilenameTemplate));
|
compiler.apply(new EvalDevToolModulePlugin("//@ sourceURL=[url]\n//# sourceURL=[url]", options.output.devtoolModuleFilenameTemplate));
|
||||||
else if(options.devtool === "hidden-sourcemap" || options.devtool === "hidden-source-map")
|
else if(options.devtool && (options.devtool.indexOf("sourcemap") >= 0 || options.devtool.indexOf("source-map") >= 0)) {
|
||||||
compiler.apply(new SourceMapDevToolPlugin(options.output.sourceMapFilename, false, options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
var hidden = options.devtool.indexOf("hidden") >= 0;
|
||||||
else if(options.devtool === "sourcemap" || options.devtool === "source-map")
|
var inline = options.devtool.indexOf("inline") >= 0;
|
||||||
compiler.apply(new SourceMapDevToolPlugin(options.output.sourceMapFilename, null, options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
var evalWrapped = options.devtool.indexOf("eval") >= 0;
|
||||||
else if(options.devtool === "@sourcemap" || options.devtool === "@source-map")
|
var cheap = options.devtool.indexOf("cheap") >= 0;
|
||||||
compiler.apply(new SourceMapDevToolPlugin(options.output.sourceMapFilename, "\n/*\n//@ sourceMappingURL=[url]\n*/", options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
var moduleMaps = options.devtool.indexOf("module") >= 0;
|
||||||
else if(options.devtool === "#sourcemap" || options.devtool === "#source-map")
|
var legacy = options.devtool.indexOf("@") >= 0;
|
||||||
compiler.apply(new SourceMapDevToolPlugin(options.output.sourceMapFilename, "\n//# sourceMappingURL=[url]", options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
var modern = options.devtool.indexOf("#") >= 0;
|
||||||
else if(options.devtool === "#@sourcemap" || options.devtool === "#@source-map")
|
var comment = legacy && modern ? "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=[url]\n*/" :
|
||||||
compiler.apply(new SourceMapDevToolPlugin(options.output.sourceMapFilename, "\n/*\n//@ sourceMappingURL=[url]\n//# sourceMappingURL=[url]\n*/", options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
legacy ? "\n/*\n//@ sourceMappingURL=[url]\n*/" :
|
||||||
else if(options.devtool === "inlinesourcemap" ||
|
modern ? "\n//# sourceMappingURL=[url]" :
|
||||||
options.devtool === "inline-sourcemap" ||
|
null;
|
||||||
options.devtool === "inline-source-map")
|
compiler.apply(new (evalWrapped ? EvalSourceMapDevToolPlugin : SourceMapDevToolPlugin)({
|
||||||
compiler.apply(new SourceMapDevToolPlugin(null, null, options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
filename: inline ? null : options.output.sourceMapFilename,
|
||||||
else if(options.devtool === "@inlinesourcemap" ||
|
moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,
|
||||||
options.devtool === "@inline-sourcemap" ||
|
fallbackModuleFilenameTemplate: options.output.devtoolFallbackModuleFilenameTemplate,
|
||||||
options.devtool === "@inline-source-map")
|
append: hidden ? false : comment,
|
||||||
compiler.apply(new SourceMapDevToolPlugin(null, "\n/*\n//@ sourceMappingURL=[url]\n*/", options.output.devtoolModuleFilenameTemplate, options.output.devtoolFallbackModuleFilenameTemplate));
|
module: moduleMaps ? true : cheap ? false : true,
|
||||||
else if(options.devtool === "#inlinesourcemap" ||
|
columns: cheap ? false : true,
|
||||||
options.devtool === "#inline-sourcemap" ||
|
lineToLine: options.output.devtoolLineToLine
|
||||||
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));
|
|
||||||
|
|
||||||
function itemToPlugin(item, name) {
|
function itemToPlugin(item, name) {
|
||||||
if(Array.isArray(item))
|
if(Array.isArray(item))
|
||||||
|
|
|
@ -38,6 +38,7 @@ function WebpackOptionsDefaulter() {
|
||||||
this.set("output.hashDigest", "hex");
|
this.set("output.hashDigest", "hex");
|
||||||
this.set("output.hashDigestLength", 20);
|
this.set("output.hashDigestLength", 20);
|
||||||
this.set("output.sourcePrefix", "\t");
|
this.set("output.sourcePrefix", "\t");
|
||||||
|
this.set("output.devtoolLineToLine", false);
|
||||||
|
|
||||||
this.set("node.console", false);
|
this.set("node.console", false);
|
||||||
this.set("node.process", true);
|
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.error) return callback(dep.module.error);
|
||||||
if(!dep.module._source) throw new Error("The module created for a LoaderDependency must have a property _source");
|
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 moduleSource = dep.module._source;
|
||||||
var source = dep.module._source.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) {
|
if(dep.module.fileDependencies) {
|
||||||
dep.module.fileDependencies.forEach(function(dep) {
|
dep.module.fileDependencies.forEach(function(dep) {
|
||||||
loaderContext.addDependency(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 modulesByHash = {};
|
||||||
var allDups = [];
|
var allDups = [];
|
||||||
modules.forEach(function(module, idx) {
|
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 hash = module.getSourceHash();
|
||||||
var dupModule = modulesByHash[hash];
|
var dupModule = modulesByHash[hash];
|
||||||
if(dupModule) {
|
if(dupModule) {
|
||||||
|
@ -81,7 +81,7 @@ DedupePlugin.prototype.apply = function(compiler) {
|
||||||
var commonModules = roots.commonModules;
|
var commonModules = roots.commonModules;
|
||||||
var initialLength = roots.initialCommonModulesLength;
|
var initialLength = roots.initialCommonModulesLength;
|
||||||
if(initialLength !== commonModules.length) {
|
if(initialLength !== commonModules.length) {
|
||||||
var template = roots[0].createTemplate(commonModules);
|
var template = roots[0].createTemplate(commonModules, roots.slice());
|
||||||
roots.template = template;
|
roots.template = template;
|
||||||
chunk.addModule(template);
|
chunk.addModule(template);
|
||||||
template.addChunk(chunk);
|
template.addChunk(chunk);
|
||||||
|
@ -185,26 +185,30 @@ DedupePlugin.prototype.apply = function(compiler) {
|
||||||
"// Check all modules for deduplicated modules",
|
"// Check all modules for deduplicated modules",
|
||||||
"for(var i in modules) {",
|
"for(var i in modules) {",
|
||||||
this.indent([
|
this.indent([
|
||||||
"switch(typeof modules[i]) {",
|
"if(Object.prototype.hasOwnProperty.call(modules, i)) {",
|
||||||
"case \"number\":",
|
|
||||||
this.indent([
|
this.indent([
|
||||||
"// Module is a copy of another module",
|
"switch(typeof modules[i]) {",
|
||||||
"modules[i] = modules[modules[i]];",
|
"case \"number\":",
|
||||||
"break;"
|
|
||||||
]),
|
|
||||||
"case \"object\":",
|
|
||||||
this.indent([
|
|
||||||
"// Module can be created from a template",
|
|
||||||
"modules[i] = (function(_m) {",
|
|
||||||
this.indent([
|
this.indent([
|
||||||
"var args = _m.slice(1), fn = modules[_m[0]];",
|
"// Module is a copy of another module",
|
||||||
"return function (a,b,c) {",
|
"modules[i] = modules[modules[i]];",
|
||||||
this.indent([
|
"break;"
|
||||||
"fn.apply(null, [a,b,c].concat(args));"
|
|
||||||
]),
|
|
||||||
"};"
|
|
||||||
]),
|
]),
|
||||||
"}(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 SourceMapSource = require("webpack-core/lib/SourceMapSource");
|
||||||
var RawSource = require("webpack-core/lib/RawSource");
|
var RawSource = require("webpack-core/lib/RawSource");
|
||||||
var RequestShortener = require("../RequestShortener");
|
var RequestShortener = require("../RequestShortener");
|
||||||
|
var ModuleFilenameHelpers = require("../ModuleFilenameHelpers");
|
||||||
var uglify = require("uglify-js");
|
var uglify = require("uglify-js");
|
||||||
|
|
||||||
function UglifyJsPlugin(options) {
|
function UglifyJsPlugin(options) {
|
||||||
|
@ -19,7 +20,6 @@ module.exports = UglifyJsPlugin;
|
||||||
|
|
||||||
UglifyJsPlugin.prototype.apply = function(compiler) {
|
UglifyJsPlugin.prototype.apply = function(compiler) {
|
||||||
var options = this.options;
|
var options = this.options;
|
||||||
var that = this;
|
|
||||||
options.test = options.test || /\.js($|\?)/i;
|
options.test = options.test || /\.js($|\?)/i;
|
||||||
|
|
||||||
var requestShortener = new RequestShortener(compiler.context);
|
var requestShortener = new RequestShortener(compiler.context);
|
||||||
|
@ -40,19 +40,25 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
|
||||||
compilation.additionalChunkAssets.forEach(function(file) {
|
compilation.additionalChunkAssets.forEach(function(file) {
|
||||||
files.push(file);
|
files.push(file);
|
||||||
});
|
});
|
||||||
files = files.filter(that.matchObject.bind(that, options));
|
files = files.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options));
|
||||||
files.forEach(function(file) {
|
files.forEach(function(file) {
|
||||||
var oldWarnFunction = uglify.AST_Node.warn_function;
|
var oldWarnFunction = uglify.AST_Node.warn_function;
|
||||||
var warnings = [];
|
var warnings = [];
|
||||||
try {
|
try {
|
||||||
var asset = compilation.assets[file];
|
var asset = compilation.assets[file];
|
||||||
var input = asset.source();
|
|
||||||
if(asset.__UglifyJsPlugin) {
|
if(asset.__UglifyJsPlugin) {
|
||||||
compilation.assets[file] = asset.__UglifyJsPlugin;
|
compilation.assets[file] = asset.__UglifyJsPlugin;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(options.sourceMap !== false) {
|
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);
|
var sourceMap = new SourceMapConsumer(inputSourceMap);
|
||||||
uglify.AST_Node.warn_function = function(warning) {
|
uglify.AST_Node.warn_function = function(warning) {
|
||||||
var match = /\[.+:([0-9]+),([0-9]+)\]/.exec(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 + "]");
|
"[" + requestShortener.shorten(original.source) + ":" + original.line + "," + original.column + "]");
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
var input = asset.source();
|
||||||
uglify.AST_Node.warn_function = function(warning) {
|
uglify.AST_Node.warn_function = function(warning) {
|
||||||
warnings.push(warning);
|
warnings.push(warning);
|
||||||
};
|
};
|
||||||
|
@ -102,7 +109,7 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
|
||||||
if(map) map = map + "";
|
if(map) map = map + "";
|
||||||
stream = stream + "";
|
stream = stream + "";
|
||||||
asset.__UglifyJsPlugin = compilation.assets[file] = (map ?
|
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));
|
new RawSource(stream));
|
||||||
if(warnings.length > 0) {
|
if(warnings.length > 0) {
|
||||||
compilation.warnings.push(new Error(file + " from UglifyJs\n" + warnings.join("\n")));
|
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",
|
"NormalModuleReplacementPlugin",
|
||||||
"ContextReplacementPlugin",
|
"ContextReplacementPlugin",
|
||||||
"IgnorePlugin",
|
"IgnorePlugin",
|
||||||
|
"WatchIgnorePlugin",
|
||||||
"BannerPlugin",
|
"BannerPlugin",
|
||||||
"PrefetchPlugin",
|
"PrefetchPlugin",
|
||||||
"AutomaticPrefetchPlugin",
|
"AutomaticPrefetchPlugin",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "webpack",
|
"name": "webpack",
|
||||||
"version": "1.7.2",
|
"version": "1.8.4",
|
||||||
"author": "Tobias Koppers @sokra",
|
"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.",
|
"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": {
|
"dependencies": {
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
"async": "~0.9.0",
|
"async": "~0.9.0",
|
||||||
"clone": "~0.1.15",
|
"clone": "~0.1.15",
|
||||||
"enhanced-resolve": "~0.8.2",
|
"enhanced-resolve": "~0.8.2",
|
||||||
|
"interpret": "^0.5.2",
|
||||||
"memory-fs": "~0.2.0",
|
"memory-fs": "~0.2.0",
|
||||||
"mkdirp": "~0.5.0",
|
"mkdirp": "~0.5.0",
|
||||||
"node-libs-browser": "~0.4.0",
|
"node-libs-browser": "~0.4.0",
|
||||||
|
@ -16,7 +17,7 @@
|
||||||
"tapable": "~0.1.8",
|
"tapable": "~0.1.8",
|
||||||
"uglify-js": "~2.4.13",
|
"uglify-js": "~2.4.13",
|
||||||
"watchpack": "^0.2.1",
|
"watchpack": "^0.2.1",
|
||||||
"webpack-core": "~0.5.0"
|
"webpack-core": "~0.6.0"
|
||||||
},
|
},
|
||||||
"licenses": [
|
"licenses": [
|
||||||
{
|
{
|
||||||
|
@ -25,6 +26,7 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"benchmark": "^1.0.0",
|
||||||
"bundle-loader": "~0.5.0",
|
"bundle-loader": "~0.5.0",
|
||||||
"coffee-loader": "~0.7.1",
|
"coffee-loader": "~0.7.1",
|
||||||
"component-webpack-plugin": "~0.2.0",
|
"component-webpack-plugin": "~0.2.0",
|
||||||
|
@ -36,6 +38,7 @@
|
||||||
"jade-loader": "~0.7.0",
|
"jade-loader": "~0.7.0",
|
||||||
"json-loader": "~0.5.1",
|
"json-loader": "~0.5.1",
|
||||||
"less-loader": "^2.0.0",
|
"less-loader": "^2.0.0",
|
||||||
|
"microtime": "^1.2.0",
|
||||||
"mocha": "~2.1.0",
|
"mocha": "~2.1.0",
|
||||||
"raw-loader": "~0.5.0",
|
"raw-loader": "~0.5.0",
|
||||||
"script-loader": "~0.6.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 should = require("should");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
|
@ -32,6 +32,9 @@ describe("TestCases", function() {
|
||||||
{ name: "devtool-eval-source-map", devtool: "#eval-source-map" },
|
{ name: "devtool-eval-source-map", devtool: "#eval-source-map" },
|
||||||
{ name: "devtool-inline-source-map", devtool: "inline-source-map" },
|
{ name: "devtool-inline-source-map", devtool: "inline-source-map" },
|
||||||
{ name: "devtool-source-map", devtool: "#@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: [
|
{ name: "minimized", plugins: [
|
||||||
new webpack.optimize.UglifyJsPlugin({
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
sourceMap: false
|
sourceMap: false
|
||||||
|
|
|
@ -41,7 +41,7 @@ library1.on("exit", function(code) {
|
||||||
bindOutput(main);
|
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",
|
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);
|
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");
|
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() {
|
it("should short-circut evaluating", function() {
|
||||||
var expr;
|
var expr;
|
||||||
var a = false && expr ? require("fail") : require("./a");
|
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