From 9f04a2d4a60afd34967fa4de05e670e49f92d0e8 Mon Sep 17 00:00:00 2001 From: Daniel Schaffer Date: Fri, 23 Aug 2019 14:21:58 -0700 Subject: [PATCH] core: add example using jQuery with es6 and `expose-loader`, add documentation for using `expose-loader` fixes #34 --- .yarn-offline-mirror/expose-loader-0.7.5.tgz | Bin 0 -> 3580 bytes README.md | 5 ++ examples/es6-jquery/README.md | 1 + examples/es6-jquery/e2e-config.json | 4 ++ examples/es6-jquery/package-lock.json | 13 +++++ examples/es6-jquery/package.json | 7 +++ examples/es6-jquery/src/commonjs-five.js | 3 ++ examples/es6-jquery/src/entry.js | 22 ++++++++ examples/es6-jquery/src/four.js | 1 + examples/es6-jquery/src/one.js | 1 + examples/es6-jquery/src/three.js | 1 + examples/es6-jquery/src/two.js | 1 + examples/es6-jquery/webpack.config.js | 50 +++++++++++++++++++ package.json | 1 + yarn.lock | 5 ++ 15 files changed, 115 insertions(+) create mode 100644 .yarn-offline-mirror/expose-loader-0.7.5.tgz create mode 100644 examples/es6-jquery/README.md create mode 100644 examples/es6-jquery/e2e-config.json create mode 100644 examples/es6-jquery/package-lock.json create mode 100644 examples/es6-jquery/package.json create mode 100644 examples/es6-jquery/src/commonjs-five.js create mode 100644 examples/es6-jquery/src/entry.js create mode 100644 examples/es6-jquery/src/four.js create mode 100644 examples/es6-jquery/src/one.js create mode 100644 examples/es6-jquery/src/three.js create mode 100644 examples/es6-jquery/src/two.js create mode 100644 examples/es6-jquery/webpack.config.js diff --git a/.yarn-offline-mirror/expose-loader-0.7.5.tgz b/.yarn-offline-mirror/expose-loader-0.7.5.tgz new file mode 100644 index 0000000000000000000000000000000000000000..bff1372aa808709b1a3d14fd1c0070d69571d2d5 GIT binary patch literal 3580 zcmVBoCywp8#Ks953|=6U&GGdP z4QikhA!*eT#GB2(*?+QsY^%Ck7_gI^<2+_(uXTJZ)ZO*$>Uv2b8@*!_?u7bozmK0KrP9v!HrzChSGiKDto z3FY#TBMbgWXtL?({CHzRv`4|r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LwT#f(r(N z!4NBR3(XA#tQB9l&yvkKEx8fVm&8Kdk9ZhMN28OO!&egh8}Vp}Z*8@Mm~U8a(eymSr0h#yRU}3K;BwLE9C4$Tgj~WNI-h&gQ&EK4^E5i^n?GO?MR6kHthO7P(9N6!S8kDYO{Fu0DnOt1M$u zdvLBi#0QA!T~ON6w9Ol#Tqc#IU?4WXto!9*20kK+3+tnjbxFGNNzxG+DiZ!+d=p(a zQ_pJZSQo7PiB#53?&%A1|!s4=sn)S~CxH4Z)_3V4;Kd zk?yLtn1QM+TwSox+N({smH91Ss~IHej-pgBxUayC^U$r4AHAFR*Ppdi8U112A8wB| z_iGzn`0j>7A@F>#A?D!f1t5LeX&gKYg@azjp2jopfr*j78OYxZWZn|wgxUy2E|a_v z4~PLr)rpp18^Y)bh013Uv&~f{vS7n!aLIUF}4s z-(+x0hb`N>F_@k*;ZsKjkAVq}`|8^dm6*iCz`Zm%R2&_eJ=>4n8&W(ow~}g=Yb&W1 zJuFwPrB&$6G5wZRTjz1qK2;&j*J)Pbly`QXRLZ~152`=Q1H!XH&KX84PoK#QhaBVF zB6IksWE#M)n9Ba^pWeUziE{fUJ=5r7_xnm&`J|MOw=1RXC#A0x)2+@0y4#Y^QPe+braUjGK|r(4SaH~;{T CSP?-0 literal 0 HcmV?d00001 diff --git a/README.md b/README.md index 3127dff..f9614e8 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,11 @@ be customized (see [Options Reference](#options-reference) below) * Vue * Replace `'vue-loader'` with `BabelMultiTargetPlugin.loader('vue-loader')` + +* `expose-loader` + * Rules using `expose-loader` must be defined _before_ rules using `BabelMultiTargetPlugin.loader()` + * Do not `import`/`require` libraries exposed with `expose-loader` - either reference them from the global scope, + or do not use `expose-loader`. You may also need to use Webpack's `ProvidePlugin`. ## Upgrading from v1.x diff --git a/examples/es6-jquery/README.md b/examples/es6-jquery/README.md new file mode 100644 index 0000000..91a9ab0 --- /dev/null +++ b/examples/es6-jquery/README.md @@ -0,0 +1 @@ +# Example: ES6 (jQuery) diff --git a/examples/es6-jquery/e2e-config.json b/examples/es6-jquery/e2e-config.json new file mode 100644 index 0000000..9b072cd --- /dev/null +++ b/examples/es6-jquery/e2e-config.json @@ -0,0 +1,4 @@ +{ + "angular": false, + "e2e_ready": true +} diff --git a/examples/es6-jquery/package-lock.json b/examples/es6-jquery/package-lock.json new file mode 100644 index 0000000..f2b6b04 --- /dev/null +++ b/examples/es6-jquery/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "webpack-babel-multi-target-plugin-example-es6-jquery", + "version": "0.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "jquery": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.1.tgz", + "integrity": "sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw==" + } + } +} diff --git a/examples/es6-jquery/package.json b/examples/es6-jquery/package.json new file mode 100644 index 0000000..6ce2ace --- /dev/null +++ b/examples/es6-jquery/package.json @@ -0,0 +1,7 @@ +{ + "name": "webpack-babel-multi-target-plugin-example-es6-jquery", + "version": "0.0.0", + "dependencies": { + "jquery": "^3.4.1" + } +} diff --git a/examples/es6-jquery/src/commonjs-five.js b/examples/es6-jquery/src/commonjs-five.js new file mode 100644 index 0000000..0646261 --- /dev/null +++ b/examples/es6-jquery/src/commonjs-five.js @@ -0,0 +1,3 @@ +const foo = () => console.log('commonjs 5') + +module.exports = foo diff --git a/examples/es6-jquery/src/entry.js b/examples/es6-jquery/src/entry.js new file mode 100644 index 0000000..2ca6792 --- /dev/null +++ b/examples/es6-jquery/src/entry.js @@ -0,0 +1,22 @@ +console.log('entry!') + +import { GTG } from '../../_shared/constants' +import { createDom } from '../../_shared/es6-dom' +import { makeItGreen } from '../../_shared/make.it.green' +import { es6 } from '../../_shared/logos' +import ready from '../../_shared/ready' + +require('./commonjs-five') + +Promise.all([]) + +async function init() { + const dom = createDom('es6-jquery', es6) + + makeItGreen() + + dom.setStatus(GTG) + ready() +} + +$(init) diff --git a/examples/es6-jquery/src/four.js b/examples/es6-jquery/src/four.js new file mode 100644 index 0000000..2062fe8 --- /dev/null +++ b/examples/es6-jquery/src/four.js @@ -0,0 +1 @@ +console.log('4') diff --git a/examples/es6-jquery/src/one.js b/examples/es6-jquery/src/one.js new file mode 100644 index 0000000..62bb704 --- /dev/null +++ b/examples/es6-jquery/src/one.js @@ -0,0 +1 @@ +console.log('1') diff --git a/examples/es6-jquery/src/three.js b/examples/es6-jquery/src/three.js new file mode 100644 index 0000000..a35be70 --- /dev/null +++ b/examples/es6-jquery/src/three.js @@ -0,0 +1 @@ +console.log('3') diff --git a/examples/es6-jquery/src/two.js b/examples/es6-jquery/src/two.js new file mode 100644 index 0000000..1f88295 --- /dev/null +++ b/examples/es6-jquery/src/two.js @@ -0,0 +1 @@ +console.log('2') diff --git a/examples/es6-jquery/webpack.config.js b/examples/es6-jquery/webpack.config.js new file mode 100644 index 0000000..bc81039 --- /dev/null +++ b/examples/es6-jquery/webpack.config.js @@ -0,0 +1,50 @@ +const { ProvidePlugin } = require('webpack') + +const BabelMultiTargetPlugin = require('../../').BabelMultiTargetPlugin + +/** + * @type {Configuration} + * + * this configuration is merged with ~/examples/webpack.common.js + **/ +module.exports = { + + entry: { + 'main': [ + './src/one.js', + './src/two.js', + './src/three.js', + './src/four.js', + './src/entry.js', + ], + }, + + module: { + rules: [ + { + test: /node_modules\/jquery/, + use: [ + { + loader: 'expose-loader', + options: 'jQuery', + }, + { + loader: 'expose-loader', + options: '$', + }, + ], + }, + { + test: /\.js$/, + use: BabelMultiTargetPlugin.loader(), + }, + ], + }, + plugins: [ + new ProvidePlugin({ + $: 'jquery', + jQuery: 'jQuery', + }), + ], + +} diff --git a/package.json b/package.json index b7fdb38..696fac2 100644 --- a/package.json +++ b/package.json @@ -109,6 +109,7 @@ "eslint": "^5.12.0", "eslint-plugin-import": "^2.14.0", "eslint-plugin-mocha": "^5.2.0", + "expose-loader": "^0.7.5", "express": "^4.16.4", "express-history-api-fallback": "^2.2.1", "file-loader": "^3.0.1", diff --git a/yarn.lock b/yarn.lock index d24767e..da3078f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3156,6 +3156,11 @@ expand-brackets@^2.1.4: snapdragon "^0.8.1" to-regex "^3.0.1" +expose-loader@^0.7.5: + version "0.7.5" + resolved "https://registry.npmjs.org/expose-loader/-/expose-loader-0.7.5.tgz#e29ea2d9aeeed3254a3faa1b35f502db9f9c3f6f" + integrity sha512-iPowgKUZkTPX5PznYsmifVj9Bob0w2wTHVkt/eYNPSzyebkUgIedmskf/kcfEIWpiWjg3JRjnW+a17XypySMuw== + express-history-api-fallback@^2.2.1: version "2.2.1" resolved "https://registry.npmjs.org/express-history-api-fallback/-/express-history-api-fallback-2.2.1.tgz#3a2ad27f7bebc90fc533d110d7c6d83097bcd057"