Import Upstream version 0.7.1

parents
yarn.lock -diff
\ No newline at end of file
node_modules
# Tasks are commented out purposfully. Will be uncommented for webpack-defaults application
sudo: false
language: node_js
branches:
only:
- master
matrix:
fast_finish: true
include:
- os: linux
node_js: '6'
env: WEBPACK_VERSION="2.2.0" JOB_PART=test
- os: linux
node_js: '4.3'
env: WEBPACK_VERSION="2.2.0" JOB_PART=test
- os: linux
node_js: '7'
env: WEBPACK_VERSION="2.2.0" JOB_PART=test
# - os: linux
# node_js: '7'
# env: WEBPACK_VERSION="2.2.0" BITHOUND_CHECK=true JOB_PART=lint
# - os: linux
# node_js: '7'
# env: WEBPACK_VERSION="2.2.0" JOB_PART=coverage
before_install:
- nvm --version
- node --version
before_script:
- if [ "$WEBPACK_VERSION" ]; then yarn add webpack@^$WEBPACK_VERSION; fi
# - if [ "$BITHOUND_CHECK" ]; then npm install -g bithound; bithound check git@github.com:$TRAVIS_REPO_SLUG.git; fi
script:
- yarn run travis:$JOB_PART
# after_success:
# - bash <(curl -s https://codecov.io/bash)
\ No newline at end of file
Copyright JS Foundation and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[![npm][npm]][npm-url]
[![deps][deps]][deps-url]
[![test][test]][test-url]
[![chat][chat]][chat-url]
<div align="center">
<!-- replace with accurate logo e.g from https://worldvectorlogo.com/ -->
<a href="https://github.com/webpack/webpack">
<img width="200" height="200" vspace="" hspace="25"
src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg">
</a>
<h1>Imports Loader</h1>
<p>The imports loader allows you to use modules that depend on specific global variables.<p>
</div>
This is useful for third-party modules that rely on global variables like `$` or `this` being the `window` object. The imports loader can add the necessary `require('whatever')` calls, so those modules work with webpack.
<h2 align="center">Install</h2>
```bash
npm install imports-loader
```
<h2 align="center">Usage</h2>
Given you have this file `example.js`
```javascript
$("img").doSomeAwesomeJqueryPluginStuff();
```
then you can inject the `$` variable into the module by configuring the imports-loader like this:
``` javascript
require("imports-loader?$=jquery!./example.js");
```
This simply prepends `var $ = require("jquery");` to `example.js`.
### Syntax
Query value | Equals
------------|-------
`angular``var angular = require("angular");`
`$=jquery` | `var $ = require("jquery");`
`define=>false` | `var define = false;`
`config=>{size:50}` | `var config = {size:50};`
`this=>window` | `(function () { ... }).call(window);`
### Multiple values
Multiple values are separated by comma `,`:
```javascript
require("imports-loader?$=jquery,angular,config=>{size:50}!./file.js");
```
### webpack.config.js
As always, you should rather configure this in your `webpack.config.js`:
```javascript
// ./webpack.config.js
module.exports = {
...
module: {
loaders: [
{
test: require.resolve("some-module"),
loader: "imports-loader?this=>window"
}
]
}
};
```
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
<h2 align="center">Typical Use Cases</h2>
### jQuery plugins
`imports-loader?$=jquery`
### Custom Angular modules
`imports-loader?angular`
### Disable AMD
There are many modules that check for a `define` function before using CommonJS. Since webpack is capable of both, they default to AMD in this case, which can be a problem if the implementation is quirky.
Then you can easily disable the AMD path by writing
```javascript
imports-loader?define=>false
```
For further hints on compatibility issues, check out [Shimming Modules](http://webpack.github.io/docs/shimming-modules.html) of the official docs.
<h2 align="center">Maintainers</h2>
<table>
<tbody>
<tr>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/166921?v=3&s=150">
</br>
<a href="https://github.com/bebraw">Juho Vepsäläinen</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars2.githubusercontent.com/u/8420490?v=3&s=150">
</br>
<a href="https://github.com/d3viant0ne">Joshua Wiens</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/533616?v=3&s=150">
</br>
<a href="https://github.com/SpaceK33z">Kees Kluskens</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/3408176?v=3&s=150">
</br>
<a href="https://github.com/TheLarkInn">Sean Larkin</a>
</td>
</tr>
<tbody>
</table>
[npm]: https://img.shields.io/npm/v/imports-loader.svg
[npm-url]: https://npmjs.com/package/imports-loader
[deps]: https://david-dm.org/webpack-contrib/imports-loader.svg
[deps-url]: https://david-dm.org/webpack-contrib/imports-loader
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
[chat-url]: https://gitter.im/webpack/webpack
[test]: http://img.shields.io/travis/webpack-contrib/imports-loader.svg
[test-url]: https://travis-ci.org/webpack-contrib/imports-loader
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var loaderUtils = require("loader-utils");
var SourceNode = require("source-map").SourceNode;
var SourceMapConsumer = require("source-map").SourceMapConsumer;
var HEADER = "/*** IMPORTS FROM imports-loader ***/\n";
module.exports = function(content, sourceMap) {
if(this.cacheable) this.cacheable();
var query = loaderUtils.getOptions(this) || {};
var imports = [];
var postfixes = [];
Object.keys(query).forEach(function(name) {
var value;
if(typeof query[name] == "string" && query[name].substr(0, 1) == ">") {
value = query[name].substr(1);
} else {
var mod = name;
if(typeof query[name] === "string") {
mod = query[name];
}
value = "require(" + JSON.stringify(mod) + ")";
}
if(name === "this") {
imports.push("(function() {");
postfixes.unshift("}.call(" + value + "));");
} else if(name.indexOf(".") !== -1) {
name.split(".").reduce(function(previous, current, index, names) {
var expr = previous + current;
if(previous.length === 0) {
imports.push("var " + expr + " = (" + current + " || {});");
} else if(index < names.length-1) {
imports.push(expr + " = {};");
} else {
imports.push(expr + " = " + value + ";");
}
return previous + current + ".";
}, "");
} else {
imports.push("var " + name + " = " + value + ";");
}
});
var prefix = HEADER + imports.join("\n") + "\n\n";
var postfix = "\n" + postfixes.join("\n");
if(sourceMap) {
var currentRequest = loaderUtils.getCurrentRequest(this);
var node = SourceNode.fromStringWithSourceMap(content, new SourceMapConsumer(sourceMap));
node.prepend(prefix);
node.add(postfix);
var result = node.toStringWithSourceMap({
file: currentRequest
});
this.callback(null, result.code, result.map.toJSON());
return;
}
return prefix + content + postfix;
}
{
"name": "imports-loader",
"version": "0.7.1",
"author": "Tobias Koppers @sokra",
"description": "imports loader module for webpack",
"scripts": {
"test": "mocha",
"travis:test": "npm run -s test"
},
"dependencies": {
"loader-utils": "^1.0.2",
"source-map": "^0.5.6"
},
"devDependencies": {
"mocha": "^3.1.2",
"should": "^11.1.1"
},
"files": [
"index.js"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/webpack/imports-loader.git"
}
}
var should = require("should");
var loader = require("../");
var HEADER = "/*** IMPORTS FROM imports-loader ***/\n";
describe("loader", function() {
it("should import nested objects", function() {
loader.call({
query: "?abc.def.ghi=>1"
}, "").should.be.eql(HEADER +
"var abc = (abc || {});\n" +
"abc.def = {};\n" +
"abc.def.ghi = 1;\n\n\n"
);
});
it("should import multiple nested objects", function() {
loader.call({
query: "?abc.def.ghi=>1,foo.bar.baz=>2"
}, "").should.be.eql(HEADER +
// First import
"var abc = (abc || {});\n" +
"abc.def = {};\n" +
"abc.def.ghi = 1;\n" +
// Second import
"var foo = (foo || {});\n" +
"foo.bar = {};\n" +
"foo.bar.baz = 2;\n\n\n"
);
});
});
This diff was suppressed by a .gitattributes entry.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment