pax_global_header00006660000000000000000000000064130542146700014514gustar00rootroot0000000000000052 comment=3c8b7f2957a1782b569b6ad61dcd1a4f4657da74 imports-loader-0.7.1/000077500000000000000000000000001305421467000144625ustar00rootroot00000000000000imports-loader-0.7.1/.gitattributes000066400000000000000000000000171305421467000173530ustar00rootroot00000000000000yarn.lock -diffimports-loader-0.7.1/.gitignore000066400000000000000000000000151305421467000164460ustar00rootroot00000000000000node_modules imports-loader-0.7.1/.travis.yml000066400000000000000000000017631305421467000166020ustar00rootroot00000000000000# 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)imports-loader-0.7.1/LICENSE000066400000000000000000000020571305421467000154730ustar00rootroot00000000000000Copyright 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. imports-loader-0.7.1/README.md000066400000000000000000000101271305421467000157420ustar00rootroot00000000000000[![npm][npm]][npm-url] [![deps][deps]][deps-url] [![test][test]][test-url] [![chat][chat]][chat-url]

Imports Loader

The imports loader allows you to use modules that depend on specific global variables.

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.

Install

```bash npm install imports-loader ```

Usage

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)

Typical Use Cases

### 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.

Maintainers


Juho Vepsäläinen

Joshua Wiens

Kees Kluskens

Sean Larkin
[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 imports-loader-0.7.1/index.js000066400000000000000000000035761305421467000161420ustar00rootroot00000000000000/* 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; } imports-loader-0.7.1/package.json000066400000000000000000000010251305421467000167460ustar00rootroot00000000000000{ "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" } } imports-loader-0.7.1/test/000077500000000000000000000000001305421467000154415ustar00rootroot00000000000000imports-loader-0.7.1/test/test.js000066400000000000000000000013401305421467000167540ustar00rootroot00000000000000var 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" ); }); }); imports-loader-0.7.1/yarn.lock000066400000000000000000000207371305421467000163160ustar00rootroot00000000000000# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # yarn lockfile v1 balanced-match@^0.4.1: version "0.4.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838" big.js@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/big.js/-/big.js-3.1.3.tgz#4cada2193652eb3ca9ec8e55c9015669c9806978" brace-expansion@^1.0.0: version "1.1.6" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.6.tgz#7197d7eaa9b87e648390ea61fc66c84427420df9" dependencies: balanced-match "^0.4.1" concat-map "0.0.1" browser-stdout@1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f" commander@2.9.0: version "2.9.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4" dependencies: graceful-readlink ">= 1.0.0" concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" debug@2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da" dependencies: ms "0.7.1" diff@1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf" emojis-list@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389" escape-string-regexp@1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" glob@7.0.5: version "7.0.5" resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.5.tgz#b4202a69099bbb4d292a7c1b95b6682b67ebdc95" dependencies: fs.realpath "^1.0.0" inflight "^1.0.4" inherits "2" minimatch "^3.0.2" once "^1.3.0" path-is-absolute "^1.0.0" "graceful-readlink@>= 1.0.0": version "1.0.1" resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" growl@1.9.2: version "1.9.2" resolved "https://registry.yarnpkg.com/growl/-/growl-1.9.2.tgz#0ea7743715db8d8de2c5ede1775e1b45ac85c02f" has-flag@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa" inflight@^1.0.4: version "1.0.6" resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" dependencies: once "^1.3.0" wrappy "1" inherits@2: version "2.0.3" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" json3@3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1" json5@^0.5.0: version "0.5.1" resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" loader-utils@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.0.2.tgz#a9f923c865a974623391a8602d031137fad74830" dependencies: big.js "^3.1.3" emojis-list "^2.0.0" json5 "^0.5.0" lodash._baseassign@^3.0.0: version "3.2.0" resolved "https://registry.yarnpkg.com/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e" dependencies: lodash._basecopy "^3.0.0" lodash.keys "^3.0.0" lodash._basecopy@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz#8da0e6a876cf344c0ad8a54882111dd3c5c7ca36" lodash._basecreate@^3.0.0: version "3.0.3" resolved "https://registry.yarnpkg.com/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz#1bc661614daa7fc311b7d03bf16806a0213cf821" lodash._getnative@^3.0.0: version "3.9.1" resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" lodash._isiterateecall@^3.0.0: version "3.0.9" resolved "https://registry.yarnpkg.com/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz#5203ad7ba425fae842460e696db9cf3e6aac057c" lodash.create@3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/lodash.create/-/lodash.create-3.1.1.tgz#d7f2849f0dbda7e04682bb8cd72ab022461debe7" dependencies: lodash._baseassign "^3.0.0" lodash._basecreate "^3.0.0" lodash._isiterateecall "^3.0.0" lodash.isarguments@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" lodash.isarray@^3.0.0: version "3.0.4" resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" lodash.keys@^3.0.0: version "3.1.2" resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a" dependencies: lodash._getnative "^3.0.0" lodash.isarguments "^3.0.0" lodash.isarray "^3.0.0" minimatch@^3.0.2: version "3.0.3" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774" dependencies: brace-expansion "^1.0.0" minimist@0.0.8: version "0.0.8" resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" mkdirp@0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" dependencies: minimist "0.0.8" mocha@^3.1.2: version "3.2.0" resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.2.0.tgz#7dc4f45e5088075171a68896814e6ae9eb7a85e3" dependencies: browser-stdout "1.3.0" commander "2.9.0" debug "2.2.0" diff "1.4.0" escape-string-regexp "1.0.5" glob "7.0.5" growl "1.9.2" json3 "3.3.2" lodash.create "3.1.1" mkdirp "0.5.1" supports-color "3.1.2" ms@0.7.1: version "0.7.1" resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098" once@^1.3.0: version "1.4.0" resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" dependencies: wrappy "1" path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" should-equal@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/should-equal/-/should-equal-1.0.1.tgz#0b6e9516f2601a9fb0bb2dcc369afa1c7e200af7" dependencies: should-type "^1.0.0" should-format@^3.0.2: version "3.0.3" resolved "https://registry.yarnpkg.com/should-format/-/should-format-3.0.3.tgz#9bfc8f74fa39205c53d38c34d717303e277124f1" dependencies: should-type "^1.3.0" should-type-adaptors "^1.0.1" should-type-adaptors@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/should-type-adaptors/-/should-type-adaptors-1.0.1.tgz#efe5553cdf68cff66e5c5f51b712dc351c77beaa" dependencies: should-type "^1.3.0" should-util "^1.0.0" should-type@^1.0.0, should-type@^1.3.0, should-type@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/should-type/-/should-type-1.4.0.tgz#0756d8ce846dfd09843a6947719dfa0d4cff5cf3" should-util@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/should-util/-/should-util-1.0.0.tgz#c98cda374aa6b190df8ba87c9889c2b4db620063" should@^11.1.1: version "11.2.0" resolved "https://registry.yarnpkg.com/should/-/should-11.2.0.tgz#7afca3182c234781d786d2278a87805b5ecf0409" dependencies: should-equal "^1.0.0" should-format "^3.0.2" should-type "^1.4.0" should-type-adaptors "^1.0.1" should-util "^1.0.0" source-map@^0.5.6: version "0.5.6" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412" supports-color@3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.1.2.tgz#72a262894d9d408b956ca05ff37b2ed8a6e2a2d5" dependencies: has-flag "^1.0.0" wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"