├── .husky ├── pre-commit └── commit-msg ├── .prettierignore ├── src ├── cjs.js ├── index.js ├── options.json └── utils.js ├── .gitattributes ├── test ├── helpers │ ├── getErrors.js │ ├── getWarnings.js │ ├── getModuleSource.js │ ├── compile.js │ ├── readAssets.js │ ├── index.js │ ├── normalizeErrors.js │ ├── execute.js │ ├── readAsset.js │ └── getCompiler.js ├── cjs.test.js ├── fixtures │ ├── simple.js │ └── inline.js ├── validate-options.test.js ├── __snapshots__ │ ├── validate-options.test.js.snap │ └── loader.test.js.snap └── loader.test.js ├── lint-staged.config.js ├── commitlint.config.js ├── eslint.config.js ├── .editorconfig ├── .gitignore ├── babel.config.js ├── .github └── workflows │ ├── dependency-review.yml │ └── nodejs.yml ├── .cspell.json ├── LICENSE ├── package.json ├── CHANGELOG.md └── README.md /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | lint-staged 2 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | commitlint --edit $1 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | /coverage 2 | /dist 3 | /node_modules 4 | /test/fixtures 5 | CHANGELOG.md -------------------------------------------------------------------------------- /src/cjs.js: -------------------------------------------------------------------------------- 1 | const loader = require("./index"); 2 | 3 | module.exports = loader.default; 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | package-lock.json -diff 2 | * text=auto 3 | bin/* eol=lf 4 | yarn.lock -diff 5 | -------------------------------------------------------------------------------- /test/helpers/getErrors.js: -------------------------------------------------------------------------------- 1 | import normalizeErrors from "./normalizeErrors"; 2 | 3 | export default (stats) => normalizeErrors(stats.compilation.errors); 4 | -------------------------------------------------------------------------------- /test/helpers/getWarnings.js: -------------------------------------------------------------------------------- 1 | import normalizeErrors from "./normalizeErrors"; 2 | 3 | export default (stats) => normalizeErrors(stats.compilation.warnings); 4 | -------------------------------------------------------------------------------- /test/cjs.test.js: -------------------------------------------------------------------------------- 1 | import src from "../src"; 2 | import cjs from "../src/cjs"; 3 | 4 | describe("cjs", () => { 5 | it("should exported", () => { 6 | expect(cjs).toEqual(src); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /lint-staged.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "*": [ 3 | "prettier --cache --write --ignore-unknown", 4 | "cspell --cache --no-must-find-files", 5 | ], 6 | "*.js": ["eslint --cache --fix"], 7 | }; 8 | -------------------------------------------------------------------------------- /test/helpers/getModuleSource.js: -------------------------------------------------------------------------------- 1 | export default (name, stats) => { 2 | const { modules } = stats.toJson({ source: true }); 3 | const module = modules.find((m) => m.name === name); 4 | 5 | return module.source; 6 | }; 7 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ["@commitlint/config-conventional"], 3 | rules: { 4 | "header-max-length": [0], 5 | "body-max-line-length": [0], 6 | "footer-max-line-length": [0], 7 | }, 8 | }; 9 | -------------------------------------------------------------------------------- /eslint.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "eslint/config"; 2 | import configs from "eslint-config-webpack/configs.js"; 3 | 4 | export default defineConfig([ 5 | { 6 | extends: [configs["recommended-dirty"]], 7 | }, 8 | ]); 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /test/helpers/compile.js: -------------------------------------------------------------------------------- 1 | export default (compiler) => 2 | new Promise((resolve, reject) => { 3 | compiler.run((error, stats) => { 4 | if (error) { 5 | return reject(error); 6 | } 7 | 8 | return resolve(stats); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | logs 3 | *.log 4 | npm-debug.log* 5 | .eslintcache 6 | .cspellcache 7 | /coverage 8 | /dist 9 | /local 10 | /reports 11 | /node_modules 12 | .DS_Store 13 | Thumbs.db 14 | .idea 15 | .vscode 16 | *.sublime-project 17 | *.sublime-workspace 18 | *.iml 19 | 20 | -------------------------------------------------------------------------------- /test/helpers/readAssets.js: -------------------------------------------------------------------------------- 1 | import readAsset from "./readAsset"; 2 | 3 | export default function readAssets(compiler, stats) { 4 | const assets = {}; 5 | 6 | for (const asset of Object.keys(stats.compilation.assets)) { 7 | assets[asset] = readAsset(asset, compiler, stats); 8 | } 9 | 10 | return assets; 11 | } 12 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | const MIN_BABEL_VERSION = 7; 2 | 3 | module.exports = (api) => { 4 | api.assertVersion(MIN_BABEL_VERSION); 5 | api.cache(true); 6 | 7 | return { 8 | presets: [ 9 | [ 10 | "@babel/preset-env", 11 | { 12 | targets: { 13 | node: "18.12.0", 14 | }, 15 | }, 16 | ], 17 | ], 18 | }; 19 | }; 20 | -------------------------------------------------------------------------------- /.github/workflows/dependency-review.yml: -------------------------------------------------------------------------------- 1 | name: "Dependency Review" 2 | on: [pull_request] 3 | 4 | permissions: 5 | contents: read 6 | 7 | jobs: 8 | dependency-review: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: "Checkout Repository" 12 | uses: actions/checkout@v5 13 | - name: "Dependency Review" 14 | uses: actions/dependency-review-action@v4 15 | -------------------------------------------------------------------------------- /.cspell.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2", 3 | "language": "en,en-gb", 4 | "words": [ 5 | "commitlint", 6 | "Koppers", 7 | "sokra", 8 | "memfs", 9 | "cspellcache", 10 | "eslintcache" 11 | ], 12 | "ignorePaths": [ 13 | "CHANGELOG.md", 14 | "package.json", 15 | "dist/**", 16 | "**/__snapshots__/**", 17 | "package-lock.json", 18 | "node_modules", 19 | "coverage", 20 | "*.log" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /test/helpers/index.js: -------------------------------------------------------------------------------- 1 | export { default as compile } from "./compile"; 2 | export { default as getCompiler } from "./getCompiler"; 3 | export { default as execute } from "./execute"; 4 | export { default as getModuleSource } from "./getModuleSource"; 5 | export { default as getErrors } from "./getErrors"; 6 | export { default as normalizeErrors } from "./normalizeErrors"; 7 | export { default as getWarnings } from "./getWarnings"; 8 | export { default as readsAssets } from "./readAssets"; 9 | export { default as readAsset } from "./readAsset"; 10 | -------------------------------------------------------------------------------- /test/helpers/normalizeErrors.js: -------------------------------------------------------------------------------- 1 | function removeCWD(str) { 2 | const isWin = process.platform === "win32"; 3 | let cwd = process.cwd(); 4 | 5 | if (isWin) { 6 | str = str.replaceAll("\\", "/"); 7 | 8 | cwd = cwd.replaceAll("\\", "/"); 9 | } 10 | 11 | return str 12 | .replace(/\(from .*?\)/, "(from `replaced original path`)") 13 | .replaceAll(new RegExp(cwd, "g"), ""); 14 | } 15 | 16 | export default (errors) => 17 | errors.map((error) => 18 | removeCWD(error.toString().split("\n").slice(0, 2).join("\n")), 19 | ); 20 | -------------------------------------------------------------------------------- /test/helpers/execute.js: -------------------------------------------------------------------------------- 1 | import Module from "node:module"; 2 | import path from "node:path"; 3 | 4 | const parentModule = module; 5 | 6 | export default (code) => { 7 | const resource = "test.js"; 8 | const module = new Module(resource, parentModule); 9 | 10 | module.paths = Module._nodeModulePaths( 11 | path.resolve(__dirname, "../fixtures"), 12 | ); 13 | module.filename = resource; 14 | 15 | module._compile( 16 | `var exportsLoader;${code};module.exports = exportsLoader;`, 17 | resource, 18 | ); 19 | 20 | return module.exports; 21 | }; 22 | -------------------------------------------------------------------------------- /test/fixtures/simple.js: -------------------------------------------------------------------------------- 1 | var Foo = Foo || {}; 2 | var Bar = Bar || {}; 3 | var Baz = { 4 | nestedNumber: '12', 5 | nestedFunction: function test() {} 6 | }; 7 | var simple = function simple() {}; 8 | var simple_foo = [1, 2, 3, 4, 5]; 9 | 10 | Foo.Image = function(width, height, data){ 11 | this.width = width || 0; 12 | this.height = height || 0; 13 | this.data = data || []; 14 | }; 15 | 16 | Bar.test = [1, 2, 3, 4]; 17 | 18 | class MyClass { 19 | myFunction() { 20 | return 12; 21 | } 22 | } 23 | 24 | const single = 'single'; 25 | 26 | const myVariable = new MyClass(); 27 | -------------------------------------------------------------------------------- /test/helpers/readAsset.js: -------------------------------------------------------------------------------- 1 | import path from "node:path"; 2 | 3 | export default (asset, compiler, stats) => { 4 | const usedFs = compiler.outputFileSystem; 5 | const outputPath = stats.compilation.outputOptions.path; 6 | 7 | let data = ""; 8 | let targetFile = asset; 9 | 10 | const queryStringIdx = targetFile.indexOf("?"); 11 | 12 | if (queryStringIdx >= 0) { 13 | targetFile = targetFile.slice(0, queryStringIdx); 14 | } 15 | 16 | try { 17 | data = usedFs.readFileSync(path.join(outputPath, targetFile)).toString(); 18 | } catch (error) { 19 | data = error.toString(); 20 | } 21 | 22 | return data; 23 | }; 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright JS Foundation and other contributors 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | 'Software'), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /test/helpers/getCompiler.js: -------------------------------------------------------------------------------- 1 | import path from "node:path"; 2 | 3 | import { Volume, createFsFromVolume } from "memfs"; 4 | import webpack from "webpack"; 5 | 6 | export default (fixture, loaderOptions = {}, config = {}) => { 7 | const fullConfig = { 8 | mode: "development", 9 | devtool: config.devtool || false, 10 | context: path.resolve(__dirname, "../fixtures"), 11 | entry: path.resolve(__dirname, "../fixtures", fixture), 12 | output: { 13 | path: path.resolve(__dirname, "../outputs"), 14 | filename: "[name].bundle.js", 15 | chunkFilename: "[name].chunk.js", 16 | library: "exportsLoader", 17 | }, 18 | module: { 19 | rules: [ 20 | { 21 | test: /\.js$/i, 22 | rules: [ 23 | { 24 | loader: path.resolve(__dirname, "../../src"), 25 | options: loaderOptions || {}, 26 | }, 27 | ], 28 | }, 29 | ], 30 | }, 31 | plugins: [], 32 | ...config, 33 | }; 34 | 35 | const compiler = webpack(fullConfig); 36 | 37 | if (!config.outputFileSystem) { 38 | compiler.outputFileSystem = createFsFromVolume(new Volume()); 39 | } 40 | 41 | return compiler; 42 | }; 43 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License http://www.opensource.org/licenses/mit-license.php 3 | Author Tobias Koppers @sokra 4 | */ 5 | import { SourceMapConsumer, SourceNode } from "source-map"; 6 | 7 | import schema from "./options.json"; 8 | import { getExports, renderExports } from "./utils"; 9 | 10 | const FOOTER = "/*** EXPORTS FROM exports-loader ***/\n"; 11 | 12 | export default function loader(content, sourceMap) { 13 | const options = this.getOptions(schema); 14 | const type = options.type || "module"; 15 | const callback = this.async(); 16 | 17 | let exports; 18 | 19 | try { 20 | exports = getExports(type, options.exports); 21 | } catch (error) { 22 | callback(error); 23 | 24 | return; 25 | } 26 | 27 | const exportsCode = renderExports(this, type, exports); 28 | 29 | if (this.sourceMap && sourceMap) { 30 | const node = SourceNode.fromStringWithSourceMap( 31 | content, 32 | new SourceMapConsumer(sourceMap), 33 | ); 34 | 35 | node.add(`\n${FOOTER}${exportsCode}`); 36 | 37 | const result = node.toStringWithSourceMap({ file: this.resourcePath }); 38 | 39 | callback(null, result.code, result.map.toJSON()); 40 | 41 | return; 42 | } 43 | 44 | callback(null, `${content}\n${FOOTER}${exportsCode}`, sourceMap); 45 | } 46 | -------------------------------------------------------------------------------- /test/fixtures/inline.js: -------------------------------------------------------------------------------- 1 | const test1 = require('../../src/cjs.js?exports=Foo!./simple.js'); 2 | const test2 = require('../../src/cjs.js?exports=Foo,Bar!./simple.js'); 3 | const test4 = require('../../src/cjs.js?exports=Foo!./simple.js'); 4 | const test5 = require('../../src/cjs.js?type=commonjs&exports=Foo!./simple.js'); 5 | const test6 = require('../../src/cjs.js?type=module&exports=Foo!./simple.js'); 6 | const test7 = require('../../src/cjs.js?type=module&exports=default%20Foo!./simple.js'); 7 | const test8 = require('../../src/cjs.js?type=module&exports=named%20Foo!./simple.js'); 8 | const test9 = require('../../src/cjs.js?type=commonjs&exports=single%20Foo!./simple.js'); 9 | const test10 = require('../../src/cjs.js?type=commonjs&exports=multiple%20Foo!./simple.js'); 10 | const test11 = require('../../src/cjs.js?type=module&exports=named%20Foo%20FooA!./simple.js'); 11 | const test12 = require('../../src/cjs.js?type=module&exports=named|Foo%20FooA,named%20Bar%20BarA!./simple.js'); 12 | const test13 = require('../../src/cjs.js?type=module&exports=named|Foo|FooA,named|Bar|BarA!./simple.js'); 13 | const test14 = require('../../src/cjs.js?type=module&exports=default|Foo!./simple.js'); 14 | 15 | module.exports = { 16 | test1, 17 | test2, 18 | test4, 19 | test5, 20 | test6, 21 | test7, 22 | test8, 23 | test9, 24 | test10, 25 | test11, 26 | test12, 27 | test13, 28 | test14 29 | }; 30 | -------------------------------------------------------------------------------- /src/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Exports Loader options", 3 | "definitions": { 4 | "ExportItemString": { 5 | "type": "string", 6 | "minLength": 1 7 | }, 8 | "ExportItemObject": { 9 | "type": "object", 10 | "additionalProperties": false, 11 | "properties": { 12 | "syntax": { 13 | "enum": ["default", "named", "single", "multiple"] 14 | }, 15 | "name": { 16 | "type": "string", 17 | "minLength": 1 18 | }, 19 | "alias": { 20 | "type": "string", 21 | "minLength": 1 22 | } 23 | }, 24 | "required": ["name"] 25 | }, 26 | "ExportItem": { 27 | "anyOf": [ 28 | { 29 | "$ref": "#/definitions/ExportItemString" 30 | }, 31 | { 32 | "$ref": "#/definitions/ExportItemObject" 33 | } 34 | ] 35 | } 36 | }, 37 | "type": "object", 38 | "additionalProperties": false, 39 | "properties": { 40 | "type": { 41 | "enum": ["commonjs", "module"], 42 | "description": "Format of generated exports.", 43 | "link": "https://github.com/webpack/exports-loader#type" 44 | }, 45 | "exports": { 46 | "anyOf": [ 47 | { 48 | "type": "string", 49 | "minLength": 1 50 | }, 51 | { 52 | "$ref": "#/definitions/ExportItem" 53 | }, 54 | { 55 | "type": "array", 56 | "items": { 57 | "$ref": "#/definitions/ExportItem" 58 | }, 59 | "minItems": 1 60 | } 61 | ], 62 | "description": "List of exports.", 63 | "link": "https://github.com/webpack/exports-loader#exports" 64 | } 65 | }, 66 | "required": ["exports"] 67 | } 68 | -------------------------------------------------------------------------------- /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | name: exports-loader 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - next 8 | pull_request: 9 | branches: 10 | - main 11 | - next 12 | 13 | permissions: 14 | contents: read 15 | 16 | jobs: 17 | lint: 18 | name: Lint - ${{ matrix.os }} - Node v${{ matrix.node-version }} 19 | 20 | env: 21 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 22 | 23 | strategy: 24 | matrix: 25 | os: [ubuntu-latest] 26 | node-version: [lts/*] 27 | 28 | runs-on: ${{ matrix.os }} 29 | 30 | concurrency: 31 | group: lint-${{ matrix.os }}-v${{ matrix.node-version }}-${{ github.ref }} 32 | cancel-in-progress: true 33 | 34 | steps: 35 | - uses: actions/checkout@v5 36 | with: 37 | fetch-depth: 0 38 | 39 | - name: Use Node.js ${{ matrix.node-version }} 40 | uses: actions/setup-node@v4 41 | with: 42 | node-version: ${{ matrix.node-version }} 43 | cache: "npm" 44 | 45 | - name: Install dependencies 46 | run: npm ci 47 | 48 | - name: Lint 49 | run: npm run lint 50 | 51 | - name: Security audit 52 | run: npm run security 53 | 54 | - name: Validate PR commits with commitlint 55 | if: github.event_name == 'pull_request' 56 | run: npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose 57 | 58 | test: 59 | name: Test - ${{ matrix.os }} - Node v${{ matrix.node-version }}, Webpack ${{ matrix.webpack-version }} 60 | 61 | strategy: 62 | matrix: 63 | os: [ubuntu-latest, windows-latest, macos-latest] 64 | node-version: [18.x, 20.x, 22.x, 24.x] 65 | webpack-version: [latest] 66 | 67 | runs-on: ${{ matrix.os }} 68 | 69 | concurrency: 70 | group: test-${{ matrix.os }}-v${{ matrix.node-version }}-${{ matrix.webpack-version }}-${{ github.ref }} 71 | cancel-in-progress: true 72 | 73 | steps: 74 | - uses: actions/checkout@v5 75 | 76 | - name: Use Node.js ${{ matrix.node-version }} 77 | uses: actions/setup-node@v4 78 | with: 79 | node-version: ${{ matrix.node-version }} 80 | cache: "npm" 81 | 82 | - name: Install dependencies 83 | run: npm ci 84 | 85 | - name: Install webpack ${{ matrix.webpack-version }} 86 | if: matrix.webpack-version != 'latest' 87 | run: npm i webpack@${{ matrix.webpack-version }} 88 | 89 | - name: Run tests for webpack version ${{ matrix.webpack-version }} 90 | run: npm run test:coverage -- --ci 91 | 92 | - name: Submit coverage data to codecov 93 | uses: codecov/codecov-action@v5 94 | with: 95 | token: ${{ secrets.CODECOV_TOKEN }} 96 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exports-loader", 3 | "version": "5.0.0", 4 | "description": "exports loader module for webpack", 5 | "keywords": [ 6 | "webpack" 7 | ], 8 | "homepage": "https://github.com/webpack/exports-loader", 9 | "bugs": "https://github.com/webpack/exports-loader/issues", 10 | "repository": "webpack/exports-loader", 11 | "funding": { 12 | "type": "opencollective", 13 | "url": "https://opencollective.com/webpack" 14 | }, 15 | "license": "MIT", 16 | "author": "Tobias Koppers @sokra", 17 | "main": "dist/cjs.js", 18 | "files": [ 19 | "dist" 20 | ], 21 | "scripts": { 22 | "start": "npm run build -- -w", 23 | "clean": "del-cli dist", 24 | "prebuild": "npm run clean", 25 | "build": "cross-env NODE_ENV=production babel src -d dist --copy-files", 26 | "commitlint": "commitlint --from=main", 27 | "security": "npm audit --production", 28 | "lint:prettier": "prettier --cache --list-different .", 29 | "lint:js": "eslint --cache .", 30 | "lint:spelling": "cspell --cache --no-must-find-files --quiet \"**/*.*\"", 31 | "lint": "npm-run-all -l -p \"lint:**\"", 32 | "fix:js": "npm run lint:js -- --fix", 33 | "fix:prettier": "npm run lint:prettier -- --write", 34 | "fix": "npm-run-all -l fix:js fix:prettier", 35 | "test:only": "cross-env NODE_ENV=test jest", 36 | "test:watch": "npm run test:only -- --watch", 37 | "test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage", 38 | "pretest": "npm run lint", 39 | "test": "npm run test:coverage", 40 | "prepare": "husky && npm run build", 41 | "release": "standard-version" 42 | }, 43 | "dependencies": { 44 | "source-map": "^0.6.1" 45 | }, 46 | "devDependencies": { 47 | "@babel/cli": "^7.24.8", 48 | "@babel/core": "^7.25.2", 49 | "@babel/preset-env": "^7.25.3", 50 | "@commitlint/cli": "^19.3.0", 51 | "@commitlint/config-conventional": "^19.2.2", 52 | "@eslint/markdown": "^7.0.0", 53 | "@stylistic/eslint-plugin": "^5.2.1", 54 | "babel-jest": "^30.0.0", 55 | "babel-loader": "^8.3.0", 56 | "cross-env": "^7.0.3", 57 | "cspell": "^8.13.1", 58 | "del": "^7.1.0", 59 | "del-cli": "^5.1.0", 60 | "eslint": "^9.0.0", 61 | "eslint-config-prettier": "^10.1.8", 62 | "eslint-config-webpack": "^4.4.1", 63 | "eslint-plugin-import": "^2.32.0", 64 | "eslint-plugin-jest": "^29.0.1", 65 | "eslint-plugin-n": "^17.21.0", 66 | "eslint-plugin-prettier": "^5.5.3", 67 | "eslint-plugin-unicorn": "^60.0.0", 68 | "husky": "^9.1.4", 69 | "jest": "^30.0.0", 70 | "lint-staged": "^15.2.8", 71 | "memfs": "^4.11.1", 72 | "npm-run-all": "^4.1.5", 73 | "prettier": "^3.3.3", 74 | "standard-version": "^9.5.0", 75 | "webpack": "^5.93.0" 76 | }, 77 | "peerDependencies": { 78 | "webpack": "^5.0.0" 79 | }, 80 | "engines": { 81 | "node": ">= 18.12.0" 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /test/validate-options.test.js: -------------------------------------------------------------------------------- 1 | import { compile, getCompiler } from "./helpers"; 2 | 3 | describe("validate options", () => { 4 | const tests = { 5 | type: { 6 | success: ["commonjs", "module"], 7 | failure: [true, false, "foo"], 8 | }, 9 | exports: { 10 | success: [ 11 | "Foo", 12 | "default Foo", 13 | "named Foo", 14 | "named Foo FooA", 15 | "named|Foo FooA", 16 | "named|Foo|FooA", 17 | ["named Foo", "named Bar"], 18 | ["named Foo FooA", "named Bar BarA"], 19 | ["default Foo", "named Bar BarA"], 20 | "single Foo", 21 | "multiple Foo", 22 | "multiple Foo FooA", 23 | ["multiple Foo", "multiple Bar"], 24 | ["multiple Foo FooA", "multiple Bar BarA"], 25 | { name: "Foo" }, 26 | { syntax: "default", name: "Foo" }, 27 | { syntax: "named", name: "Foo" }, 28 | { syntax: "single", name: "Foo" }, 29 | { syntax: "multiple", name: "Foo" }, 30 | { syntax: "named", name: "Foo", alias: "FooA" }, 31 | { syntax: "multiple", name: "Foo", alias: "FooA" }, 32 | ["Foo", { syntax: "default", name: "Bar" }], 33 | [ 34 | { syntax: "named", name: "Foo" }, 35 | { syntax: "named", name: "Bar" }, 36 | ], 37 | ], 38 | failure: [ 39 | true, 40 | () => {}, 41 | [1, 2, 3], 42 | { syntax: "default" }, 43 | { alias: "FooA" }, 44 | { syntax: "foo", name: "Foo" }, 45 | { name: "" }, 46 | { name: "Foo", alias: "" }, 47 | ], 48 | }, 49 | }; 50 | 51 | function stringifyValue(value) { 52 | if ( 53 | Array.isArray(value) || 54 | (value && typeof value === "object" && value.constructor === Object) 55 | ) { 56 | return JSON.stringify(value); 57 | } 58 | 59 | return value; 60 | } 61 | 62 | async function createTestCase(key, value, type) { 63 | it(`should ${ 64 | type === "success" ? "successfully validate" : "throw an error on" 65 | } the "${key}" option with "${stringifyValue(value)}" value`, async () => { 66 | const getOptions = (key, value) => { 67 | if (key === "type") { 68 | return { [key]: value, exports: "Foo" }; 69 | } 70 | 71 | if (key === "exports") { 72 | let isModule = false; 73 | 74 | if (typeof value === "string") { 75 | isModule = value.includes("default") || value.includes("named"); 76 | } else if (Array.isArray(value)) { 77 | isModule = value.some((item) => 78 | typeof item === "string" 79 | ? item.includes("default") || item.includes("named") 80 | : item.syntax 81 | ? item.syntax === "default" || item.syntax === "named" 82 | : false, 83 | ); 84 | } else { 85 | isModule = 86 | value.syntax && 87 | (value.syntax === "default" || value.syntax === "named"); 88 | } 89 | 90 | return { type: isModule ? "module" : "commonjs", [key]: value }; 91 | } 92 | 93 | return { [key]: value }; 94 | }; 95 | 96 | const compiler = getCompiler("simple.js", getOptions(key, value)); 97 | 98 | let stats; 99 | 100 | try { 101 | stats = await compile(compiler); 102 | } finally { 103 | if (type === "success") { 104 | expect(stats.hasErrors()).toBe(false); 105 | } else if (type === "failure") { 106 | const { 107 | compilation: { errors }, 108 | } = stats; 109 | 110 | expect(errors).toHaveLength(1); 111 | expect(() => { 112 | throw new Error(errors[0].error.message); 113 | }).toThrowErrorMatchingSnapshot(); 114 | } 115 | } 116 | }); 117 | } 118 | 119 | for (const [key, values] of Object.entries(tests)) { 120 | for (const type of Object.keys(values)) { 121 | for (const value of values[type]) { 122 | createTestCase(key, value, type); 123 | } 124 | } 125 | } 126 | }); 127 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ## [5.0.0](https://github.com/webpack-contrib/exports-loader/compare/v4.0.0...v5.0.0) (2024-01-16) 6 | 7 | 8 | ### ⚠ BREAKING CHANGES 9 | 10 | * minimum supported Node.js version is `18.12.0` ([#146](https://github.com/webpack-contrib/exports-loader/issues/146)) ([0c658f1](https://github.com/webpack-contrib/exports-loader/commit/0c658f1bdf8d8ef07adc66a491862edbcd23d306)) 11 | 12 | ## [4.0.0](https://github.com/webpack-contrib/exports-loader/compare/v3.1.0...v4.0.0) (2022-05-17) 13 | 14 | 15 | ### ⚠ BREAKING CHANGES 16 | 17 | * minimum supported `Node.js` version is `14.15.0` 18 | 19 | ## [3.1.0](https://github.com/webpack-contrib/exports-loader/compare/v3.0.0...v3.1.0) (2021-10-21) 20 | 21 | 22 | ### Features 23 | 24 | * output helpful descriptions and links on errors ([#66](https://github.com/webpack-contrib/exports-loader/issues/66)) ([ba96dda](https://github.com/webpack-contrib/exports-loader/commit/ba96ddacca7d8272cd75efb9607f5498e623f549)) 25 | 26 | ## [3.0.0](https://github.com/webpack-contrib/exports-loader/compare/v2.0.0...v3.0.0) (2021-05-17) 27 | 28 | 29 | ### ⚠ BREAKING CHANGES 30 | 31 | * minimum supported `Node.js` version is `12.13.0` 32 | 33 | ## [2.0.0](https://github.com/webpack-contrib/exports-loader/compare/v1.1.1...v2.0.0) (2021-01-11) 34 | 35 | 36 | ### ⚠ BREAKING CHANGES 37 | 38 | * minimum supported `webpack` version is `5` ([#58](https://github.com/webpack-contrib/exports-loader/issues/58)) ([9176392](https://github.com/webpack-contrib/exports-loader/commit/917639250b68e8c1b10769dcb43d751e12c52677)) 39 | * inline syntax was changed: `[]` is no longer supported (i.e. `exports-loader?exports[]=myVariable&exports[]=myFunction!./file.js`), please use `,` (i.e. `exports-loader?exports=myVariable,myFunction!./file.js`) 40 | * removed filename template support for export names and aliases (i.e. `[name]`) due unstable behaviour in some cases and very rarely used 41 | 42 | ### [1.1.1](https://github.com/webpack-contrib/exports-loader/compare/v1.1.0...v1.1.1) (2020-10-09) 43 | 44 | ### Chore 45 | 46 | * update `schema-utils` 47 | 48 | ## [1.1.0](https://github.com/webpack-contrib/exports-loader/compare/v1.0.1...v1.1.0) (2020-06-24) 49 | 50 | 51 | ### Features 52 | 53 | * "|" character can be used as delimiter for inline string syntax ([#46](https://github.com/webpack-contrib/exports-loader/issues/46)) ([e0bc930](https://github.com/webpack-contrib/exports-loader/commit/e0bc930d84d83107f3d7bf1c761f9af8bca26931)) 54 | 55 | ## [1.0.1](https://github.com/webpack-contrib/exports-loader/compare/v1.0.0...v1.0.1) (2020-06-17) 56 | 57 | 58 | ### Bug Fixes 59 | 60 | * better error reporting ([#44](https://github.com/webpack-contrib/exports-loader/issues/44)) ([0397393](https://github.com/webpack-contrib/exports-loader/commit/03973937083d5e7217e74f18bd62b1e7d2615a89)) 61 | 62 | ## [1.0.0](https://github.com/webpack-contrib/exports-loader/compare/v0.7.0...v1.0.0) (2020-06-10) 63 | 64 | 65 | ### ⚠ BREAKING CHANGES 66 | 67 | * minimum supported Node.js version is `10.13` 68 | * minimum supported `webpack` version is `4` 69 | * `exports` values moved to the `exports` option, please [read](https://github.com/webpack-contrib/exports-loader#options) 70 | * generates ES module named exports by default (`exports { Foo }`) 71 | * multiple exports in the `inline` syntax were changed, please [read](https://github.com/webpack-contrib/exports-loader#inline) 72 | 73 | ### Features 74 | 75 | * validate options 76 | * support webpack 5 77 | * implemented the `type` option (exports can be CommonsJS or ES module format) 78 | * exports can be described using a string or an object value 79 | * implemented the ability to generate multiple experts 80 | * improved support of `inline` usage 81 | 82 | 83 | ### Bug Fixes 84 | 85 | * `export` is not used anymore for CommonJS module format 86 | 87 | 88 | # [0.7.0](https://github.com/webpack-contrib/exports-loader/compare/v0.6.4...v0.7.0) (2018-02-05) 89 | 90 | 91 | ### Features 92 | 93 | * **index:** add interpolation support (`loaderUtils.interpolateName`) ([#21](https://github.com/webpack-contrib/exports-loader/issues/21)) ([201de63](https://github.com/webpack-contrib/exports-loader/commit/201de63)) 94 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | function forError(item) { 2 | return typeof item === "string" 3 | ? item 4 | : `\n${JSON.stringify(item, null, " ")}\n`; 5 | } 6 | 7 | function splitCommand(command) { 8 | const result = command.split("|").flatMap((item) => item.split(" ")); 9 | 10 | for (const item of result) { 11 | if (!item) { 12 | throw new Error( 13 | `Invalid command "${item}" in "${command}" for exports. There must be only one separator: " ", or "|"`, 14 | ); 15 | } 16 | } 17 | 18 | return result; 19 | } 20 | 21 | function resolveExports(type, item) { 22 | let result; 23 | 24 | if (typeof item === "string") { 25 | const noWhitespaceItem = item.trim(); 26 | 27 | if (noWhitespaceItem.length === 0) { 28 | throw new Error(`Invalid "${item}" value for export`); 29 | } 30 | 31 | const splittedItem = splitCommand(noWhitespaceItem); 32 | 33 | if (splittedItem.length > 3) { 34 | throw new Error(`Invalid "${item}" value for export`); 35 | } 36 | 37 | if (splittedItem.length === 1) { 38 | result = { 39 | syntax: type === "module" ? "named" : "multiple", 40 | name: splittedItem[0], 41 | 42 | alias: undefined, 43 | }; 44 | } else { 45 | result = { 46 | syntax: splittedItem[0], 47 | name: splittedItem[1], 48 | alias: 49 | typeof splittedItem[2] !== "undefined" ? splittedItem[2] : undefined, 50 | }; 51 | } 52 | } else { 53 | result = { syntax: type === "module" ? "named" : "multiple", ...item }; 54 | } 55 | 56 | if (!["default", "named", "single", "multiple"].includes(result.syntax)) { 57 | throw new Error( 58 | `Unknown "${result.syntax}" syntax export in "${forError(item)}" value`, 59 | ); 60 | } 61 | 62 | if ( 63 | ["default", "single"].includes(result.syntax) && 64 | typeof result.alias !== "undefined" 65 | ) { 66 | throw new Error( 67 | `The "${result.syntax}" syntax can't have "${ 68 | result.alias 69 | }" alias in "${forError(item)}" value`, 70 | ); 71 | } 72 | 73 | if ( 74 | type === "commonjs" && 75 | (result.syntax === "default" || result.syntax === "named") 76 | ) { 77 | throw new Error( 78 | `The "${type}" format can't be used with the "${ 79 | result.syntax 80 | }" syntax export in "${forError(item)}" value`, 81 | ); 82 | } 83 | 84 | if ( 85 | type === "module" && 86 | (result.syntax === "single" || result.syntax === "multiple") 87 | ) { 88 | throw new Error( 89 | `The "${type}" format can't be used with the "${ 90 | result.syntax 91 | }" syntax export in "${forError(item)}" value`, 92 | ); 93 | } 94 | 95 | return result; 96 | } 97 | 98 | function getIdentifiers(array) { 99 | return array.reduce((accumulator, item) => { 100 | if (typeof item.alias !== "undefined") { 101 | accumulator.push({ type: "alias", value: item.alias }); 102 | 103 | return accumulator; 104 | } 105 | 106 | accumulator.push({ type: "name", value: item.name }); 107 | 108 | return accumulator; 109 | }, []); 110 | } 111 | 112 | function duplicateBy(array, key) { 113 | return array.filter((a, aIndex) => 114 | array.some((b, bIndex) => b[key] === a[key] && aIndex !== bIndex), 115 | ); 116 | } 117 | 118 | function getExports(type, exports) { 119 | const exportItems = 120 | typeof exports === "string" && exports.includes(",") 121 | ? exports.split(",") 122 | : exports; 123 | 124 | const result = Array.isArray(exportItems) 125 | ? exportItems.map((item) => resolveExports(type, item)) 126 | : [resolveExports(type, exportItems)]; 127 | 128 | const hasMultipleDefault = result.filter( 129 | ({ syntax }) => syntax === "default" || syntax === "single", 130 | ); 131 | 132 | if (hasMultipleDefault.length > 1) { 133 | throw new Error( 134 | `The "${type}" format can't have multiple "${ 135 | type === "module" ? "default" : "single" 136 | }" exports in "\n${JSON.stringify(exports, null, " ")}\n" value`, 137 | ); 138 | } 139 | 140 | const identifiers = getIdentifiers(result); 141 | const duplicates = duplicateBy(identifiers, "value"); 142 | 143 | if (duplicates.length > 0) { 144 | throw new Error( 145 | `Duplicate ${duplicates 146 | .map((identifier) => `"${identifier.value}" (as "${identifier.type}")`) 147 | .join(", ")} identifiers found in "\n${JSON.stringify( 148 | exports, 149 | null, 150 | " ", 151 | )}\n" value`, 152 | ); 153 | } 154 | 155 | return result; 156 | } 157 | 158 | function renderExports(loaderContext, type, exports) { 159 | let code = ""; 160 | 161 | const defaultExport = exports.filter( 162 | ({ syntax }) => syntax === "default" || syntax === "single", 163 | ); 164 | const namedExports = exports.filter( 165 | ({ syntax }) => syntax === "named" || syntax === "multiple", 166 | ); 167 | 168 | if (defaultExport.length > 0) { 169 | switch (type) { 170 | case "commonjs": 171 | code += "module.exports = "; 172 | break; 173 | case "module": 174 | code += "export default "; 175 | break; 176 | } 177 | 178 | code += `${defaultExport[0].name};\n`; 179 | } 180 | 181 | if (namedExports.length > 0) { 182 | switch (type) { 183 | case "commonjs": 184 | code += "module.exports = {\n"; 185 | break; 186 | case "module": 187 | code += "export {\n"; 188 | break; 189 | } 190 | 191 | for (const [i, namedExport] of namedExports.entries()) { 192 | const needComma = i < namedExports.length - 1; 193 | const { name } = namedExport; 194 | 195 | const alias = namedExport.alias || undefined; 196 | 197 | code += ` ${ 198 | type === "commonjs" 199 | ? alias 200 | ? `${JSON.stringify(alias)}: (${name})` 201 | : `${name}` 202 | : `${name}${alias ? ` as ${alias}` : ""}` 203 | }${needComma ? ",\n" : ""}`; 204 | } 205 | 206 | code += "\n};\n"; 207 | } 208 | 209 | return code; 210 | } 211 | 212 | export { getExports, renderExports }; 213 | -------------------------------------------------------------------------------- /test/__snapshots__/validate-options.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`validate options should throw an error on the "exports" option with "() => {}" value 1`] = ` 4 | "Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema. 5 | - options.exports should be one of these: 6 | non-empty string | non-empty string | object { name, syntax?, alias? } | [non-empty string | object { name, syntax?, alias? }, ...] (should not have fewer than 1 item) 7 | -> List of exports. 8 | -> Read more at https://github.com/webpack/exports-loader#exports 9 | Details: 10 | * options.exports should be a non-empty string. 11 | * options.exports should be one of these: 12 | non-empty string | object { name, syntax?, alias? } 13 | Details: 14 | * options.exports should be a non-empty string. 15 | * options.exports should be an object: 16 | object { name, syntax?, alias? } 17 | * options.exports should be an array: 18 | [non-empty string | object { name, syntax?, alias? }, ...] (should not have fewer than 1 item)" 19 | `; 20 | 21 | exports[`validate options should throw an error on the "exports" option with "[1,2,3]" value 1`] = ` 22 | "Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema. 23 | - options.exports should be one of these: 24 | non-empty string | non-empty string | object { name, syntax?, alias? } | [non-empty string | object { name, syntax?, alias? }, ...] (should not have fewer than 1 item) 25 | -> List of exports. 26 | -> Read more at https://github.com/webpack/exports-loader#exports 27 | Details: 28 | * options.exports[2] should be one of these: 29 | non-empty string | object { name, syntax?, alias? } 30 | Details: 31 | * options.exports[1] should be one of these: 32 | non-empty string | object { name, syntax?, alias? } 33 | Details: 34 | * options.exports[0] should be one of these: 35 | non-empty string | object { name, syntax?, alias? } 36 | Details: 37 | * options.exports[0] should be a non-empty string. 38 | * options.exports[0] should be an object: 39 | object { name, syntax?, alias? } 40 | * options.exports[1] should be a non-empty string. 41 | * options.exports[1] should be an object: 42 | object { name, syntax?, alias? } 43 | * options.exports[2] should be a non-empty string. 44 | * options.exports[2] should be an object: 45 | object { name, syntax?, alias? }" 46 | `; 47 | 48 | exports[`validate options should throw an error on the "exports" option with "{"alias":"FooA"}" value 1`] = ` 49 | "Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema. 50 | - options.exports misses the property 'name'. Should be: 51 | non-empty string" 52 | `; 53 | 54 | exports[`validate options should throw an error on the "exports" option with "{"name":""}" value 1`] = ` 55 | "Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema. 56 | - options.exports.name should be a non-empty string." 57 | `; 58 | 59 | exports[`validate options should throw an error on the "exports" option with "{"name":"Foo","alias":""}" value 1`] = ` 60 | "Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema. 61 | - options.exports.alias should be a non-empty string." 62 | `; 63 | 64 | exports[`validate options should throw an error on the "exports" option with "{"syntax":"default"}" value 1`] = ` 65 | "Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema. 66 | - options.exports misses the property 'name'. Should be: 67 | non-empty string" 68 | `; 69 | 70 | exports[`validate options should throw an error on the "exports" option with "{"syntax":"foo","name":"Foo"}" value 1`] = ` 71 | "Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema. 72 | - options.exports.syntax should be one of these: 73 | "default" | "named" | "single" | "multiple"" 74 | `; 75 | 76 | exports[`validate options should throw an error on the "exports" option with "true" value 1`] = ` 77 | "Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema. 78 | - options.exports should be one of these: 79 | non-empty string | non-empty string | object { name, syntax?, alias? } | [non-empty string | object { name, syntax?, alias? }, ...] (should not have fewer than 1 item) 80 | -> List of exports. 81 | -> Read more at https://github.com/webpack/exports-loader#exports 82 | Details: 83 | * options.exports should be a non-empty string. 84 | * options.exports should be one of these: 85 | non-empty string | object { name, syntax?, alias? } 86 | Details: 87 | * options.exports should be a non-empty string. 88 | * options.exports should be an object: 89 | object { name, syntax?, alias? } 90 | * options.exports should be an array: 91 | [non-empty string | object { name, syntax?, alias? }, ...] (should not have fewer than 1 item)" 92 | `; 93 | 94 | exports[`validate options should throw an error on the "type" option with "false" value 1`] = ` 95 | "Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema. 96 | - options.type should be one of these: 97 | "commonjs" | "module" 98 | -> Format of generated exports. 99 | -> Read more at https://github.com/webpack/exports-loader#type" 100 | `; 101 | 102 | exports[`validate options should throw an error on the "type" option with "foo" value 1`] = ` 103 | "Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema. 104 | - options.type should be one of these: 105 | "commonjs" | "module" 106 | -> Format of generated exports. 107 | -> Read more at https://github.com/webpack/exports-loader#type" 108 | `; 109 | 110 | exports[`validate options should throw an error on the "type" option with "true" value 1`] = ` 111 | "Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema. 112 | - options.type should be one of these: 113 | "commonjs" | "module" 114 | -> Format of generated exports. 115 | -> Read more at https://github.com/webpack/exports-loader#type" 116 | `; 117 | -------------------------------------------------------------------------------- /test/loader.test.js: -------------------------------------------------------------------------------- 1 | import path from "node:path"; 2 | 3 | import { 4 | compile, 5 | execute, 6 | getCompiler, 7 | getErrors, 8 | getModuleSource, 9 | getWarnings, 10 | readAsset, 11 | } from "./helpers"; 12 | 13 | describe("loader", () => { 14 | it("should work with string value", async () => { 15 | const compiler = getCompiler("simple.js", { 16 | exports: "Foo", 17 | }); 18 | const stats = await compile(compiler); 19 | 20 | expect(getModuleSource("./simple.js", stats)).toMatchSnapshot("module"); 21 | expect( 22 | execute(readAsset("main.bundle.js", compiler, stats)), 23 | ).toMatchSnapshot("result"); 24 | expect(getErrors(stats)).toMatchSnapshot("errors"); 25 | expect(getWarnings(stats)).toMatchSnapshot("warnings"); 26 | }); 27 | 28 | it("should work with object value", async () => { 29 | const compiler = getCompiler("simple.js", { 30 | exports: { name: "Foo" }, 31 | }); 32 | const stats = await compile(compiler); 33 | 34 | expect(getModuleSource("./simple.js", stats)).toMatchSnapshot("module"); 35 | expect( 36 | execute(readAsset("main.bundle.js", compiler, stats)), 37 | ).toMatchSnapshot("result"); 38 | expect(getErrors(stats)).toMatchSnapshot("errors"); 39 | expect(getWarnings(stats)).toMatchSnapshot("warnings"); 40 | }); 41 | 42 | it("should work with object value (syntax, name and alias)", async () => { 43 | const compiler = getCompiler("simple.js", { 44 | exports: { 45 | syntax: "named", 46 | name: "Foo", 47 | alias: "FooA", 48 | }, 49 | }); 50 | const stats = await compile(compiler); 51 | 52 | expect(getModuleSource("./simple.js", stats)).toMatchSnapshot("module"); 53 | expect( 54 | execute(readAsset("main.bundle.js", compiler, stats)), 55 | ).toMatchSnapshot("result"); 56 | expect(getErrors(stats)).toMatchSnapshot("errors"); 57 | expect(getWarnings(stats)).toMatchSnapshot("warnings"); 58 | }); 59 | 60 | it('should work with object value with "default" syntax', async () => { 61 | const compiler = getCompiler("simple.js", { 62 | exports: { 63 | syntax: "default", 64 | name: "Foo", 65 | }, 66 | }); 67 | const stats = await compile(compiler); 68 | 69 | expect(getModuleSource("./simple.js", stats)).toMatchSnapshot("module"); 70 | expect( 71 | execute(readAsset("main.bundle.js", compiler, stats)), 72 | ).toMatchSnapshot("result"); 73 | expect(getErrors(stats)).toMatchSnapshot("errors"); 74 | expect(getWarnings(stats)).toMatchSnapshot("warnings"); 75 | }); 76 | 77 | it("should work with multiple string values", async () => { 78 | const compiler = getCompiler("simple.js", { 79 | exports: ["Foo", "Bar"], 80 | }); 81 | const stats = await compile(compiler); 82 | 83 | expect(getModuleSource("./simple.js", stats)).toMatchSnapshot("module"); 84 | expect( 85 | execute(readAsset("main.bundle.js", compiler, stats)), 86 | ).toMatchSnapshot("result"); 87 | expect(getErrors(stats)).toMatchSnapshot("errors"); 88 | expect(getWarnings(stats)).toMatchSnapshot("warnings"); 89 | }); 90 | 91 | it("should work with multiple object and string values", async () => { 92 | const compiler = getCompiler("simple.js", { 93 | exports: [ 94 | "Foo", 95 | { syntax: "default", name: "Bar" }, 96 | { syntax: "named", name: "Baz", alias: "BarA" }, 97 | ], 98 | }); 99 | const stats = await compile(compiler); 100 | 101 | expect(getModuleSource("./simple.js", stats)).toMatchSnapshot("module"); 102 | expect( 103 | execute(readAsset("main.bundle.js", compiler, stats)), 104 | ).toMatchSnapshot("result"); 105 | expect(getErrors(stats)).toMatchSnapshot("errors"); 106 | expect(getWarnings(stats)).toMatchSnapshot("warnings"); 107 | }); 108 | 109 | it("should work with inline syntax", async () => { 110 | const compiler = getCompiler("inline.js", {}, { module: undefined }); 111 | const stats = await compile(compiler); 112 | 113 | expect(getModuleSource("./inline.js", stats)).toMatchSnapshot("module"); 114 | expect( 115 | execute(readAsset("main.bundle.js", compiler, stats)), 116 | ).toMatchSnapshot("result"); 117 | expect(getErrors(stats)).toMatchSnapshot("errors"); 118 | expect(getWarnings(stats)).toMatchSnapshot("warnings"); 119 | }); 120 | 121 | it('should work with source maps when the "devtool" option is enabled', async () => { 122 | const compiler = getCompiler( 123 | "simple.js", 124 | {}, 125 | { 126 | devtool: "source-map", 127 | module: { 128 | rules: [ 129 | { 130 | test: /\.js$/i, 131 | rules: [ 132 | { 133 | loader: path.resolve(__dirname, "../src"), 134 | options: { exports: "Foo" }, 135 | }, 136 | { 137 | loader: "babel-loader", 138 | }, 139 | ], 140 | }, 141 | ], 142 | }, 143 | }, 144 | ); 145 | const stats = await compile(compiler); 146 | 147 | expect(getModuleSource("./simple.js", stats)).toMatchSnapshot("module"); 148 | expect( 149 | execute(readAsset("main.bundle.js", compiler, stats)), 150 | ).toMatchSnapshot("result"); 151 | expect(getErrors(stats)).toMatchSnapshot("errors"); 152 | expect(getWarnings(stats)).toMatchSnapshot("warnings"); 153 | }); 154 | 155 | it('should not work with source maps when the "devtool" options are disabled', async () => { 156 | const compiler = getCompiler( 157 | "simple.js", 158 | {}, 159 | { 160 | devtool: false, 161 | module: { 162 | rules: [ 163 | { 164 | test: /\.js$/i, 165 | rules: [ 166 | { 167 | loader: path.resolve(__dirname, "../src"), 168 | options: { exports: "Foo" }, 169 | }, 170 | { 171 | loader: "babel-loader", 172 | }, 173 | ], 174 | }, 175 | ], 176 | }, 177 | }, 178 | ); 179 | const stats = await compile(compiler); 180 | 181 | expect(getModuleSource("./simple.js", stats)).toMatchSnapshot("module"); 182 | expect( 183 | execute(readAsset("main.bundle.js", compiler, stats)), 184 | ).toMatchSnapshot("result"); 185 | expect(getErrors(stats)).toMatchSnapshot("errors"); 186 | expect(getWarnings(stats)).toMatchSnapshot("warnings"); 187 | }); 188 | 189 | function createSuccessCase(type, exports) { 190 | it(`should work with the "${type}" module format for ${JSON.stringify( 191 | exports, 192 | )} export list`, async () => { 193 | const compiler = getCompiler("simple.js", { type, exports }); 194 | const stats = await compile(compiler); 195 | 196 | expect(getModuleSource("./simple.js", stats)).toMatchSnapshot("module"); 197 | expect( 198 | execute(readAsset("main.bundle.js", compiler, stats)), 199 | ).toMatchSnapshot("result"); 200 | expect(getErrors(stats)).toMatchSnapshot("errors"); 201 | expect(getWarnings(stats)).toMatchSnapshot("warnings"); 202 | }); 203 | } 204 | 205 | function createFailedCase(type, exports) { 206 | it(`should work with the "${type}" module format for ${JSON.stringify( 207 | exports, 208 | )} export list`, async () => { 209 | const compiler = getCompiler("simple.js", { type, exports }); 210 | const stats = await compile(compiler); 211 | 212 | expect(getErrors(stats)).toMatchSnapshot("errors"); 213 | expect(getWarnings(stats)).toMatchSnapshot("warnings"); 214 | }); 215 | } 216 | // 217 | createSuccessCase("commonjs", "Foo"); 218 | createSuccessCase("commonjs", " Foo "); 219 | createFailedCase("commonjs", "default"); 220 | createFailedCase("commonjs", "default Foo"); 221 | createFailedCase("commonjs", { syntax: "default", name: "Foo" }); 222 | createFailedCase("commonjs", "named Foo"); 223 | createSuccessCase("commonjs", "single Foo"); 224 | createSuccessCase("commonjs", "single single"); 225 | createFailedCase("commonjs", "single Foo FooA"); 226 | createFailedCase("commonjs", { 227 | syntax: "single", 228 | name: "Foo", 229 | alias: "FooA", 230 | }); 231 | createSuccessCase("commonjs", "multiple Foo"); 232 | createSuccessCase("commonjs", "multiple Foo FooA"); 233 | createSuccessCase("commonjs", "multiple Foo Foo-Bar"); 234 | createSuccessCase("commonjs", "multiple|Foo"); 235 | createSuccessCase("commonjs", "multiple|Foo|FooA"); 236 | createSuccessCase("commonjs", ["Foo", "Bar"]); 237 | createSuccessCase("commonjs", ["multiple Foo", "multiple Bar"]); 238 | createSuccessCase("commonjs", ["multiple Foo FooA", "multiple Bar BarA"]); 239 | createSuccessCase("commonjs", [ 240 | "multiple myVariable.myFunction myFunction", 241 | "multiple Bar BarA", 242 | ]); 243 | createFailedCase("commonjs", "multiple Foo"); 244 | createFailedCase("commonjs", "multiple Foo FooA FooB"); 245 | createFailedCase("commonjs", ["single Foo", "single Bar"]); 246 | createFailedCase("commonjs", ["multiple Foo", "multiple Foo"]); 247 | createFailedCase("commonjs", ["multiple Foo", "multiple Bar Foo"]); 248 | createFailedCase("commonjs", ["multiple Foo Bar", "multiple Bar"]); 249 | createFailedCase("commonjs", ["multiple Foo Baz", "multiple Bar Baz"]); 250 | createFailedCase("commonjs", [ 251 | "multiple myVariable.myFunction", 252 | "multiple Bar myVariable.myFunction", 253 | ]); 254 | createFailedCase("commonjs", [ 255 | "multiple myVariable.myFunction foo.bar", 256 | "multiple Bar foo.bar", 257 | ]); 258 | createFailedCase("commonjs", "unknown Foo"); 259 | createFailedCase("commonjs", { syntax: "unknown", name: "Foo" }); 260 | createFailedCase("commonjs", "`invalid`"); 261 | createFailedCase("commonjs", " "); 262 | createFailedCase("commonjs", " "); 263 | createFailedCase("commonjs", " "); 264 | createFailedCase("commonjs", " "); 265 | 266 | createSuccessCase("module", "Foo"); 267 | createSuccessCase("module", " Foo "); 268 | createFailedCase("module", "default"); 269 | createFailedCase("module", "single Foo"); 270 | createFailedCase("module", { syntax: "single", name: "Foo" }); 271 | createFailedCase("module", "multiple Foo"); 272 | createSuccessCase("module", "default Foo"); 273 | createFailedCase("module", "default default"); 274 | createFailedCase("module", "default Foo FooA"); 275 | createFailedCase("module", { 276 | syntax: "single", 277 | name: "Foo", 278 | alias: "FooA", 279 | }); 280 | createSuccessCase("module", "named Foo"); 281 | createSuccessCase("module", "named Foo FooA"); 282 | createSuccessCase("module", "named|Foo"); 283 | createSuccessCase("module", "named|Foo|FooA"); 284 | createSuccessCase("module", ["Foo", "Bar"]); 285 | createSuccessCase("module", ["named Foo", "named Bar"]); 286 | createSuccessCase("module", ["named Foo FooA", "named Bar BarA"]); 287 | createSuccessCase("module", ["named Foo default", "named Bar BarA"]); 288 | createSuccessCase("module", ["default Foo", "named Bar"]); 289 | createSuccessCase("module", ["default Foo", "named Bar BarA"]); 290 | createSuccessCase("module", ["default Foo", "named Bar BarA", "named Baz"]); 291 | createFailedCase("module", "named Foo FooA FooB"); 292 | createFailedCase("module", ["default Foo", "default Bar"]); 293 | createFailedCase("module", ["named Foo", "named Foo"]); 294 | createFailedCase("module", ["named Foo", "named Bar Foo"]); 295 | createFailedCase("module", ["named Foo Bar", "named Bar"]); 296 | createFailedCase("module", ["named Foo Baz", "named Bar Baz"]); 297 | createFailedCase("module", "unknown Foo"); 298 | createFailedCase("module", { syntax: "unknown", name: "Foo" }); 299 | createFailedCase("module", "`invalid`"); 300 | createFailedCase("module", " "); 301 | createFailedCase("module", " "); 302 | createFailedCase("module", " "); 303 | createFailedCase("module", " "); 304 | }); 305 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 |
6 | 7 | [![npm][npm]][npm-url] 8 | [![node][node]][node-url] 9 | [![tests][tests]][tests-url] 10 | [![coverage][cover]][cover-url] 11 | [![discussion][discussion]][discussion-url] 12 | [![size][size]][size-url] 13 | 14 | # exports-loader 15 | 16 | Allows you to set up exports using `module.exports` or `export` for source files. 17 | 18 | Useful when a source file does not contain exports or when something is not exported. 19 | 20 | For more information on compatibility issues, refer to the [Shimming](https://webpack.js.org/guides/shimming/) guide in the official documentation. 21 | 22 | > [!WARNING] 23 | > 24 | > By default, the loader generates exports using ES module syntax. 25 | 26 | > [!WARNING] 27 | > 28 | > Be careful: modifying existing exports (`export`, `module.exports`, or `exports`) or adding new exports can lead to errors. 29 | 30 | ## Getting Started 31 | 32 | To begin, you'll need to install `exports-loader`: 33 | 34 | ```console 35 | npm install exports-loader --save-dev 36 | ``` 37 | 38 | or 39 | 40 | ```console 41 | yarn add -D exports-loader 42 | ``` 43 | 44 | or 45 | 46 | ```console 47 | pnpm add -D exports-loader 48 | ``` 49 | 50 | ### Inline 51 | 52 | The `|` or `%20` (space) allow to separate the `syntax`, `name` and `alias` of export. 53 | 54 | The documentation and syntax examples can be read [here](#syntax). 55 | 56 | > [!WARNING] 57 | > 58 | > `%20` represents a space in a query string because spaces are not allowed in URLs. 59 | 60 | Then add the loader to the desired `import` statement or `require` calls. For example: 61 | 62 | ```js 63 | import { myFunction } from "exports-loader?exports=myFunction!./file.js"; 64 | // Adds the following code to the file's source: 65 | // 66 | // ... 67 | // Code 68 | // ... 69 | // 70 | // export { myFunction } 71 | 72 | myFunction("Hello world"); 73 | ``` 74 | 75 | ```js 76 | import { 77 | myFunction, 78 | myVariable, 79 | } from "exports-loader?exports=myVariable,myFunction!./file.js"; 80 | // Adds the following code to the file's source: 81 | // 82 | // ... 83 | // Code 84 | // ... 85 | // 86 | // export { myVariable, myFunction }; 87 | 88 | const newVariable = `${myVariable}!!!`; 89 | 90 | console.log(newVariable); 91 | 92 | myFunction("Hello world"); 93 | ``` 94 | 95 | ```js 96 | const { 97 | myFunction, 98 | } = require("exports-loader?type=commonjs&exports=myFunction!./file.js"); 99 | // Adds the following code to the file's source: 100 | // 101 | // ... 102 | // Code 103 | // ... 104 | // 105 | // module.exports = { myFunction } 106 | 107 | myFunction("Hello world"); 108 | ``` 109 | 110 | ```js 111 | // Alternative syntax: 112 | // import myFunction from 'exports-loader?exports=default%20myFunction!./file.js'; 113 | import myFunction from "exports-loader?exports=default|myFunction!./file.js"; 114 | // `%20` is space in a query string, equivalently `default myFunction` 115 | // Adds the following code to the file's source: 116 | // 117 | // ... 118 | // Code 119 | // ... 120 | // 121 | // exports default myFunction; 122 | 123 | myFunction("Hello world"); 124 | ``` 125 | 126 | ```js 127 | const myFunction = require("exports-loader?type=commonjs&exports=single|myFunction!./file.js"); 128 | // `|` is separator in a query string, equivalently `single|myFunction` 129 | // Adds the following code to the file's source: 130 | // 131 | // ... 132 | // Code 133 | // ... 134 | // 135 | // module.exports = myFunction; 136 | 137 | myFunction("Hello world"); 138 | ``` 139 | 140 | ```js 141 | import { myFunctionAlias } from "exports-loader?exports=named|myFunction|myFunctionAlias!./file.js"; 142 | // `|` is separator in a query string, equivalently `named|myFunction|myFunctionAlias` 143 | // Adds the following code to the file's source: 144 | // 145 | // ... 146 | // Code 147 | // ... 148 | // 149 | // exports { myFunction as myFunctionAlias }; 150 | 151 | myFunctionAlias("Hello world"); 152 | ``` 153 | 154 | Descriptions of string values can be found in the documentation below. 155 | 156 | ### Using Configuration 157 | 158 | **webpack.config.js** 159 | 160 | ```js 161 | module.exports = { 162 | module: { 163 | rules: [ 164 | { 165 | // You can use `regexp` 166 | // test: /vendor\.js/$ 167 | test: require.resolve("./path/to/vendor.js"), 168 | loader: "exports-loader", 169 | options: { 170 | exports: "myFunction", 171 | }, 172 | }, 173 | ], 174 | }, 175 | }; 176 | ``` 177 | 178 | Finally, run `webpack` using the method you normally use (e.g., via CLI or an npm script). 179 | 180 | ## Options 181 | 182 | | Name | Type | Default | Description | 183 | | :-----------------------: | :---------------------------------------: | :---------: | :-------------------------- | 184 | | **[`type`](#type)** | `{String}` | `module` | Format of generated exports | 185 | | **[`exports`](#exports)** | `{String\|Object\|Array}` | `undefined` | List of exports | 186 | 187 | ### `type` 188 | 189 | Type: `String` 190 | Default: `module` 191 | 192 | Format of generated exports. 193 | 194 | Possible values - `commonjs` (CommonJS module syntax) and `module` (ES module syntax). 195 | 196 | #### `commonjs` 197 | 198 | **webpack.config.js** 199 | 200 | ```js 201 | module.exports = { 202 | module: { 203 | rules: [ 204 | { 205 | test: require.resolve("./path/to/vendor.js"), 206 | loader: "exports-loader", 207 | options: { 208 | type: "commonjs", 209 | exports: "Foo", 210 | }, 211 | }, 212 | ], 213 | }, 214 | }; 215 | ``` 216 | 217 | Generate output: 218 | 219 | ```js 220 | // ... 221 | // Code 222 | // ... 223 | 224 | module.exports = { Foo }; 225 | ``` 226 | 227 | #### `module` 228 | 229 | **webpack.config.js** 230 | 231 | ```js 232 | module.exports = { 233 | module: { 234 | rules: [ 235 | { 236 | test: require.resolve("./path/to/vendor.js"), 237 | loader: "exports-loader", 238 | options: { 239 | type: "module", 240 | exports: "Foo", 241 | }, 242 | }, 243 | ], 244 | }, 245 | }; 246 | ``` 247 | 248 | Generate output: 249 | 250 | 251 | 252 | ```js 253 | // ... 254 | // Code 255 | // ... 256 | 257 | export { Foo }; 258 | ``` 259 | 260 | ### `exports` 261 | 262 | Type: `String|Array` 263 | Default: `undefined` 264 | 265 | List of exports. 266 | 267 | #### `String` 268 | 269 | Allows to use a string to describe an export. 270 | 271 | ##### `Syntax` 272 | 273 | The `|` or `%20` (space) allow to separate the `syntax`, `name` and `alias` of export. 274 | 275 | String syntax - `[[syntax] [name] [alias]]` or `[[syntax]|[name]|[alias]]`, where: 276 | 277 | - `[syntax]` (**may be omitted**) - 278 | - if `type` is `module`- can be `default` and `named`, 279 | - if `type` is `commonjs`- can be `single` and `multiple` 280 | 281 | - `[name]` - name of an exported value (**required**) 282 | - `[alias]` - alias of an exported value (**may be omitted**) 283 | 284 | Examples: 285 | 286 | - `[Foo]` - generates `export { Foo };`. 287 | - `[default Foo]` - generates `export default Foo;`. 288 | - `[named Foo]` - generates `export { Foo };`. 289 | - `[named Foo FooA]` - generates `export { Foo as FooA };`. 290 | - `[single Foo]` - generates `module.exports = Foo;`. 291 | - `[multiple Foo]` - generates `module.exports = { Foo };`. 292 | - `[multiple Foo FooA]` - generates `module.exports = { 'FooA': Foo };`. 293 | - `[named [name] [name]Alias]` - generates ES module named exports and exports a value equal to the filename under other name., for `single.js` it will be `single` and `singleAlias`, generates `export { single as singleAlias };`. 294 | 295 | > [!WARNING] 296 | > 297 | > You need to set `type: "commonjs"` to use `single` or `multiple` syntaxes. 298 | 299 | > [!WARNING] 300 | > 301 | > Aliases can't be used together with `default` or `single` syntaxes. 302 | 303 | ##### Examples 304 | 305 | ###### ES Module Default Export 306 | 307 | **webpack.config.js** 308 | 309 | ```js 310 | module.exports = { 311 | module: { 312 | rules: [ 313 | { 314 | test: require.resolve("./path/to/vendor.js"), 315 | loader: "exports-loader", 316 | options: { 317 | exports: "default Foo", 318 | }, 319 | }, 320 | ], 321 | }, 322 | }; 323 | ``` 324 | 325 | Generate output: 326 | 327 | ```js 328 | // ... 329 | // Code 330 | // ... 331 | 332 | export default Foo; 333 | ``` 334 | 335 | ###### ES Module Named Exports 336 | 337 | **webpack.config.js** 338 | 339 | ```js 340 | module.exports = { 341 | module: { 342 | rules: [ 343 | { 344 | test: require.resolve("./path/to/vendor.js"), 345 | loader: "exports-loader", 346 | options: { 347 | exports: "named Foo FooA", 348 | }, 349 | }, 350 | ], 351 | }, 352 | }; 353 | ``` 354 | 355 | Generate output: 356 | 357 | 358 | 359 | ```js 360 | // ... 361 | // Code 362 | // ... 363 | 364 | export { Foo as FooA }; 365 | ``` 366 | 367 | ###### CommonJS Single Export 368 | 369 | **webpack.config.js** 370 | 371 | ```js 372 | module.exports = { 373 | module: { 374 | rules: [ 375 | { 376 | test: require.resolve("./path/to/vendor.js"), 377 | loader: "exports-loader", 378 | options: { 379 | type: "commonjs", 380 | exports: "single Foo", 381 | }, 382 | }, 383 | ], 384 | }, 385 | }; 386 | ``` 387 | 388 | Generate output: 389 | 390 | ```js 391 | // ... 392 | // Code 393 | // ... 394 | 395 | module.exports = Foo; 396 | ``` 397 | 398 | ###### CommonJS Multiple Exports 399 | 400 | **webpack.config.js** 401 | 402 | ```js 403 | module.exports = { 404 | module: { 405 | rules: [ 406 | { 407 | test: require.resolve("./path/to/vendor.js"), 408 | loader: "exports-loader", 409 | options: { 410 | type: "commonjs", 411 | exports: "multiple Foo FooA", 412 | }, 413 | }, 414 | ], 415 | }, 416 | }; 417 | ``` 418 | 419 | Generate output: 420 | 421 | ```js 422 | // ... 423 | // Code 424 | // ... 425 | 426 | module.exports = { FooA: Foo }; 427 | ``` 428 | 429 | #### `Object` 430 | 431 | Allows to use an object to describe an export. 432 | 433 | Properties: 434 | 435 | - `syntax` - can be `default` or `named` for the `module` type (`ES modules` module format), and `single` or `multiple` for the `commonjs` type (`CommonJS` module format) (**may be omitted**) 436 | - `name` - name of an exported value (**required**) 437 | - `alias` - alias of an exported value (**may be omitted**) 438 | 439 | ##### Examples 440 | 441 | ###### ES Module Default Export 442 | 443 | **webpack.config.js** 444 | 445 | ```js 446 | module.exports = { 447 | module: { 448 | rules: [ 449 | { 450 | test: require.resolve("./path/to/vendor.js"), 451 | loader: "exports-loader", 452 | options: { 453 | exports: { 454 | syntax: "default", 455 | name: "Foo", 456 | }, 457 | }, 458 | }, 459 | ], 460 | }, 461 | }; 462 | ``` 463 | 464 | Generate output: 465 | 466 | ```js 467 | // ... 468 | // Code 469 | // ... 470 | 471 | export default Foo; 472 | ``` 473 | 474 | ###### ES Module Named Exports 475 | 476 | **webpack.config.js** 477 | 478 | ```js 479 | module.exports = { 480 | module: { 481 | rules: [ 482 | { 483 | test: require.resolve("./path/to/vendor.js"), 484 | loader: "exports-loader", 485 | options: { 486 | exports: { 487 | syntax: "named", 488 | name: "Foo", 489 | alias: "FooA", 490 | }, 491 | }, 492 | }, 493 | ], 494 | }, 495 | }; 496 | ``` 497 | 498 | Generate output: 499 | 500 | 501 | 502 | ```js 503 | // ... 504 | // Code 505 | // ... 506 | 507 | export { Foo as FooA }; 508 | ``` 509 | 510 | ###### CommonJS Single Export 511 | 512 | **webpack.config.js** 513 | 514 | ```js 515 | module.exports = { 516 | module: { 517 | rules: [ 518 | { 519 | test: require.resolve("./path/to/vendor.js"), 520 | loader: "exports-loader", 521 | options: { 522 | type: "commonjs", 523 | exports: { 524 | syntax: "single", 525 | name: "Foo", 526 | }, 527 | }, 528 | }, 529 | ], 530 | }, 531 | }; 532 | ``` 533 | 534 | Generate output: 535 | 536 | ```js 537 | // ... 538 | // Code 539 | // ... 540 | 541 | module.exports = Foo; 542 | ``` 543 | 544 | ###### CommonJS Multiple Exports 545 | 546 | **webpack.config.js** 547 | 548 | ```js 549 | module.exports = { 550 | module: { 551 | rules: [ 552 | { 553 | test: require.resolve("./path/to/vendor.js"), 554 | loader: "exports-loader", 555 | options: { 556 | type: "commonjs", 557 | exports: { 558 | syntax: "multiple", 559 | name: "Foo", 560 | alias: "FooA", 561 | }, 562 | }, 563 | }, 564 | ], 565 | }, 566 | }; 567 | ``` 568 | 569 | Generate output: 570 | 571 | ```js 572 | // ... 573 | // Code 574 | // ... 575 | 576 | module.exports = { FooA: Foo }; 577 | ``` 578 | 579 | #### `Array` 580 | 581 | Allow to specify multiple exports. Each item can be a [`string`](https://github.com/webpack/exports-loader#string) or an [`object`](https://github.com/webpack/exports-loader#object). 582 | 583 | > [!WARNING] 584 | > 585 | > Not possible to use both `single` and `multiple` syntaxes together due to CommonJS format limitations. 586 | 587 | > [!WARNING] 588 | > 589 | > Not possible to use multiple `default` values due to ES module format limitations. 590 | 591 | > [!WARNING] 592 | > 593 | > Not possible to use multiple `single` values due to CommonJS format limitations. 594 | 595 | ##### Examples 596 | 597 | ###### CommonJS Multiple Exports 598 | 599 | **webpack.config.js** 600 | 601 | ```js 602 | module.exports = { 603 | module: { 604 | rules: [ 605 | { 606 | test: require.resolve("./path/to/vendor.js"), 607 | loader: "exports-loader", 608 | options: { 609 | type: "commonjs", 610 | exports: ["Foo", "multiple Bar", "multiple Baz BazA"], 611 | }, 612 | }, 613 | ], 614 | }, 615 | }; 616 | ``` 617 | 618 | Generate output: 619 | 620 | ```js 621 | // ... 622 | // Code 623 | // ... 624 | 625 | module.exports = { Bar, BazA: Bar, Foo }; 626 | ``` 627 | 628 | ###### ES Module Default Export And Named Exports Together 629 | 630 | **webpack.config.js** 631 | 632 | ```js 633 | module.exports = { 634 | module: { 635 | rules: [ 636 | { 637 | test: require.resolve("./path/to/vendor.js"), 638 | loader: "exports-loader", 639 | options: { 640 | exports: ["default Foo", "named Bar BarA"], 641 | }, 642 | }, 643 | ], 644 | }, 645 | }; 646 | ``` 647 | 648 | Generate output: 649 | 650 | 651 | 652 | ```js 653 | // ... 654 | // Code 655 | // ... 656 | 657 | export default Foo; 658 | export { Bar as BarA }; 659 | ``` 660 | 661 | ###### Named Exports 662 | 663 | **webpack.config.js** 664 | 665 | ```js 666 | module.exports = { 667 | module: { 668 | rules: [ 669 | { 670 | test: require.resolve("./path/to/vendor.js"), 671 | loader: "exports-loader", 672 | options: { 673 | exports: [ 674 | { syntax: "named", name: "Foo", alias: "FooA" }, 675 | { syntax: "named", name: "Bar" }, 676 | "Baz", 677 | ], 678 | }, 679 | }, 680 | ], 681 | }, 682 | }; 683 | ``` 684 | 685 | Generate output: 686 | 687 | 688 | 689 | ```js 690 | // ... 691 | // Code 692 | // ... 693 | 694 | export { Foo as FooA, Bar, Baz }; 695 | ``` 696 | 697 | ## Contributing 698 | 699 | We welcome all contributions! 700 | 701 | If you're new here, please take a moment to review our contributing guidelines. 702 | 703 | [CONTRIBUTING](https://github.com/webpack/exports-loader?tab=contributing-ov-file#contributing) 704 | 705 | ## License 706 | 707 | [MIT](./LICENSE) 708 | 709 | [npm]: https://img.shields.io/npm/v/exports-loader.svg 710 | [npm-url]: https://npmjs.com/package/exports-loader 711 | [node]: https://img.shields.io/node/v/exports-loader.svg 712 | [node-url]: https://nodejs.org 713 | [tests]: https://github.com/webpack/exports-loader/workflows/exports-loader/badge.svg 714 | [tests-url]: https://github.com/webpack/exports-loader/actions 715 | [cover]: https://codecov.io/gh/webpack/exports-loader/branch/main/graph/badge.svg 716 | [cover-url]: https://codecov.io/gh/webpack/exports-loader 717 | [discussion]: https://img.shields.io/github/discussions/webpack/webpack 718 | [discussion-url]: https://github.com/webpack/webpack/discussions 719 | [size]: https://packagephobia.now.sh/badge?p=exports-loader 720 | [size-url]: https://packagephobia.now.sh/result?p=exports-loader 721 | -------------------------------------------------------------------------------- /test/__snapshots__/loader.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`loader should not work with source maps when the "devtool" options are disabled: errors 1`] = `[]`; 4 | 5 | exports[`loader should not work with source maps when the "devtool" options are disabled: module 1`] = ` 6 | "var Foo = Foo || {}; 7 | var Bar = Bar || {}; 8 | var Baz = { 9 | nestedNumber: '12', 10 | nestedFunction: function test() {} 11 | }; 12 | var simple = function simple() {}; 13 | var simple_foo = [1, 2, 3, 4, 5]; 14 | Foo.Image = function (width, height, data) { 15 | this.width = width || 0; 16 | this.height = height || 0; 17 | this.data = data || []; 18 | }; 19 | Bar.test = [1, 2, 3, 4]; 20 | class MyClass { 21 | myFunction() { 22 | return 12; 23 | } 24 | } 25 | const single = 'single'; 26 | const myVariable = new MyClass(); 27 | /*** EXPORTS FROM exports-loader ***/ 28 | export { 29 | Foo 30 | }; 31 | " 32 | `; 33 | 34 | exports[`loader should not work with source maps when the "devtool" options are disabled: result 1`] = ` 35 | { 36 | "Foo": { 37 | "Image": [Function], 38 | }, 39 | } 40 | `; 41 | 42 | exports[`loader should not work with source maps when the "devtool" options are disabled: warnings 1`] = `[]`; 43 | 44 | exports[`loader should work with inline syntax: errors 1`] = `[]`; 45 | 46 | exports[`loader should work with inline syntax: module 1`] = ` 47 | "const test1 = require('../../src/cjs.js?exports=Foo!./simple.js'); 48 | const test2 = require('../../src/cjs.js?exports=Foo,Bar!./simple.js'); 49 | const test4 = require('../../src/cjs.js?exports=Foo!./simple.js'); 50 | const test5 = require('../../src/cjs.js?type=commonjs&exports=Foo!./simple.js'); 51 | const test6 = require('../../src/cjs.js?type=module&exports=Foo!./simple.js'); 52 | const test7 = require('../../src/cjs.js?type=module&exports=default%20Foo!./simple.js'); 53 | const test8 = require('../../src/cjs.js?type=module&exports=named%20Foo!./simple.js'); 54 | const test9 = require('../../src/cjs.js?type=commonjs&exports=single%20Foo!./simple.js'); 55 | const test10 = require('../../src/cjs.js?type=commonjs&exports=multiple%20Foo!./simple.js'); 56 | const test11 = require('../../src/cjs.js?type=module&exports=named%20Foo%20FooA!./simple.js'); 57 | const test12 = require('../../src/cjs.js?type=module&exports=named|Foo%20FooA,named%20Bar%20BarA!./simple.js'); 58 | const test13 = require('../../src/cjs.js?type=module&exports=named|Foo|FooA,named|Bar|BarA!./simple.js'); 59 | const test14 = require('../../src/cjs.js?type=module&exports=default|Foo!./simple.js'); 60 | 61 | module.exports = { 62 | test1, 63 | test2, 64 | test4, 65 | test5, 66 | test6, 67 | test7, 68 | test8, 69 | test9, 70 | test10, 71 | test11, 72 | test12, 73 | test13, 74 | test14 75 | }; 76 | " 77 | `; 78 | 79 | exports[`loader should work with inline syntax: result 1`] = ` 80 | { 81 | "test1": { 82 | "Foo": { 83 | "Image": [Function], 84 | }, 85 | }, 86 | "test10": { 87 | "Foo": { 88 | "Image": [Function], 89 | }, 90 | }, 91 | "test11": { 92 | "FooA": { 93 | "Image": [Function], 94 | }, 95 | }, 96 | "test12": { 97 | "BarA": { 98 | "test": [ 99 | 1, 100 | 2, 101 | 3, 102 | 4, 103 | ], 104 | }, 105 | "FooA": { 106 | "Image": [Function], 107 | }, 108 | }, 109 | "test13": { 110 | "BarA": { 111 | "test": [ 112 | 1, 113 | 2, 114 | 3, 115 | 4, 116 | ], 117 | }, 118 | "FooA": { 119 | "Image": [Function], 120 | }, 121 | }, 122 | "test14": { 123 | "default": { 124 | "Image": [Function], 125 | }, 126 | }, 127 | "test2": { 128 | "Bar": { 129 | "test": [ 130 | 1, 131 | 2, 132 | 3, 133 | 4, 134 | ], 135 | }, 136 | "Foo": { 137 | "Image": [Function], 138 | }, 139 | }, 140 | "test4": { 141 | "Foo": { 142 | "Image": [Function], 143 | }, 144 | }, 145 | "test5": { 146 | "Foo": { 147 | "Image": [Function], 148 | }, 149 | }, 150 | "test6": { 151 | "Foo": { 152 | "Image": [Function], 153 | }, 154 | }, 155 | "test7": { 156 | "default": { 157 | "Image": [Function], 158 | }, 159 | }, 160 | "test8": { 161 | "Foo": { 162 | "Image": [Function], 163 | }, 164 | }, 165 | "test9": { 166 | "Image": [Function], 167 | }, 168 | } 169 | `; 170 | 171 | exports[`loader should work with inline syntax: warnings 1`] = `[]`; 172 | 173 | exports[`loader should work with multiple object and string values: errors 1`] = `[]`; 174 | 175 | exports[`loader should work with multiple object and string values: module 1`] = ` 176 | "var Foo = Foo || {}; 177 | var Bar = Bar || {}; 178 | var Baz = { 179 | nestedNumber: '12', 180 | nestedFunction: function test() {} 181 | }; 182 | var simple = function simple() {}; 183 | var simple_foo = [1, 2, 3, 4, 5]; 184 | 185 | Foo.Image = function(width, height, data){ 186 | this.width = width || 0; 187 | this.height = height || 0; 188 | this.data = data || []; 189 | }; 190 | 191 | Bar.test = [1, 2, 3, 4]; 192 | 193 | class MyClass { 194 | myFunction() { 195 | return 12; 196 | } 197 | } 198 | 199 | const single = 'single'; 200 | 201 | const myVariable = new MyClass(); 202 | 203 | /*** EXPORTS FROM exports-loader ***/ 204 | export default Bar; 205 | export { 206 | Foo, 207 | Baz as BarA 208 | }; 209 | " 210 | `; 211 | 212 | exports[`loader should work with multiple object and string values: result 1`] = ` 213 | { 214 | "BarA": { 215 | "nestedFunction": [Function], 216 | "nestedNumber": "12", 217 | }, 218 | "Foo": { 219 | "Image": [Function], 220 | }, 221 | "default": { 222 | "test": [ 223 | 1, 224 | 2, 225 | 3, 226 | 4, 227 | ], 228 | }, 229 | } 230 | `; 231 | 232 | exports[`loader should work with multiple object and string values: warnings 1`] = `[]`; 233 | 234 | exports[`loader should work with multiple string values: errors 1`] = `[]`; 235 | 236 | exports[`loader should work with multiple string values: module 1`] = ` 237 | "var Foo = Foo || {}; 238 | var Bar = Bar || {}; 239 | var Baz = { 240 | nestedNumber: '12', 241 | nestedFunction: function test() {} 242 | }; 243 | var simple = function simple() {}; 244 | var simple_foo = [1, 2, 3, 4, 5]; 245 | 246 | Foo.Image = function(width, height, data){ 247 | this.width = width || 0; 248 | this.height = height || 0; 249 | this.data = data || []; 250 | }; 251 | 252 | Bar.test = [1, 2, 3, 4]; 253 | 254 | class MyClass { 255 | myFunction() { 256 | return 12; 257 | } 258 | } 259 | 260 | const single = 'single'; 261 | 262 | const myVariable = new MyClass(); 263 | 264 | /*** EXPORTS FROM exports-loader ***/ 265 | export { 266 | Foo, 267 | Bar 268 | }; 269 | " 270 | `; 271 | 272 | exports[`loader should work with multiple string values: result 1`] = ` 273 | { 274 | "Bar": { 275 | "test": [ 276 | 1, 277 | 2, 278 | 3, 279 | 4, 280 | ], 281 | }, 282 | "Foo": { 283 | "Image": [Function], 284 | }, 285 | } 286 | `; 287 | 288 | exports[`loader should work with multiple string values: warnings 1`] = `[]`; 289 | 290 | exports[`loader should work with object value (syntax, name and alias): errors 1`] = `[]`; 291 | 292 | exports[`loader should work with object value (syntax, name and alias): module 1`] = ` 293 | "var Foo = Foo || {}; 294 | var Bar = Bar || {}; 295 | var Baz = { 296 | nestedNumber: '12', 297 | nestedFunction: function test() {} 298 | }; 299 | var simple = function simple() {}; 300 | var simple_foo = [1, 2, 3, 4, 5]; 301 | 302 | Foo.Image = function(width, height, data){ 303 | this.width = width || 0; 304 | this.height = height || 0; 305 | this.data = data || []; 306 | }; 307 | 308 | Bar.test = [1, 2, 3, 4]; 309 | 310 | class MyClass { 311 | myFunction() { 312 | return 12; 313 | } 314 | } 315 | 316 | const single = 'single'; 317 | 318 | const myVariable = new MyClass(); 319 | 320 | /*** EXPORTS FROM exports-loader ***/ 321 | export { 322 | Foo as FooA 323 | }; 324 | " 325 | `; 326 | 327 | exports[`loader should work with object value (syntax, name and alias): result 1`] = ` 328 | { 329 | "FooA": { 330 | "Image": [Function], 331 | }, 332 | } 333 | `; 334 | 335 | exports[`loader should work with object value (syntax, name and alias): warnings 1`] = `[]`; 336 | 337 | exports[`loader should work with object value with "default" syntax: errors 1`] = `[]`; 338 | 339 | exports[`loader should work with object value with "default" syntax: module 1`] = ` 340 | "var Foo = Foo || {}; 341 | var Bar = Bar || {}; 342 | var Baz = { 343 | nestedNumber: '12', 344 | nestedFunction: function test() {} 345 | }; 346 | var simple = function simple() {}; 347 | var simple_foo = [1, 2, 3, 4, 5]; 348 | 349 | Foo.Image = function(width, height, data){ 350 | this.width = width || 0; 351 | this.height = height || 0; 352 | this.data = data || []; 353 | }; 354 | 355 | Bar.test = [1, 2, 3, 4]; 356 | 357 | class MyClass { 358 | myFunction() { 359 | return 12; 360 | } 361 | } 362 | 363 | const single = 'single'; 364 | 365 | const myVariable = new MyClass(); 366 | 367 | /*** EXPORTS FROM exports-loader ***/ 368 | export default Foo; 369 | " 370 | `; 371 | 372 | exports[`loader should work with object value with "default" syntax: result 1`] = ` 373 | { 374 | "default": { 375 | "Image": [Function], 376 | }, 377 | } 378 | `; 379 | 380 | exports[`loader should work with object value with "default" syntax: warnings 1`] = `[]`; 381 | 382 | exports[`loader should work with object value: errors 1`] = `[]`; 383 | 384 | exports[`loader should work with object value: module 1`] = ` 385 | "var Foo = Foo || {}; 386 | var Bar = Bar || {}; 387 | var Baz = { 388 | nestedNumber: '12', 389 | nestedFunction: function test() {} 390 | }; 391 | var simple = function simple() {}; 392 | var simple_foo = [1, 2, 3, 4, 5]; 393 | 394 | Foo.Image = function(width, height, data){ 395 | this.width = width || 0; 396 | this.height = height || 0; 397 | this.data = data || []; 398 | }; 399 | 400 | Bar.test = [1, 2, 3, 4]; 401 | 402 | class MyClass { 403 | myFunction() { 404 | return 12; 405 | } 406 | } 407 | 408 | const single = 'single'; 409 | 410 | const myVariable = new MyClass(); 411 | 412 | /*** EXPORTS FROM exports-loader ***/ 413 | export { 414 | Foo 415 | }; 416 | " 417 | `; 418 | 419 | exports[`loader should work with object value: result 1`] = ` 420 | { 421 | "Foo": { 422 | "Image": [Function], 423 | }, 424 | } 425 | `; 426 | 427 | exports[`loader should work with object value: warnings 1`] = `[]`; 428 | 429 | exports[`loader should work with source maps when the "devtool" option is enabled: errors 1`] = `[]`; 430 | 431 | exports[`loader should work with source maps when the "devtool" option is enabled: module 1`] = ` 432 | "var Foo = Foo || {}; 433 | var Bar = Bar || {}; 434 | var Baz = { 435 | nestedNumber: '12', 436 | nestedFunction: function test() {} 437 | }; 438 | var simple = function simple() {}; 439 | var simple_foo = [1, 2, 3, 4, 5]; 440 | Foo.Image = function (width, height, data) { 441 | this.width = width || 0; 442 | this.height = height || 0; 443 | this.data = data || []; 444 | }; 445 | Bar.test = [1, 2, 3, 4]; 446 | class MyClass { 447 | myFunction() { 448 | return 12; 449 | } 450 | } 451 | const single = 'single'; 452 | const myVariable = new MyClass(); 453 | /*** EXPORTS FROM exports-loader ***/ 454 | export { 455 | Foo 456 | }; 457 | " 458 | `; 459 | 460 | exports[`loader should work with source maps when the "devtool" option is enabled: result 1`] = `{}`; 461 | 462 | exports[`loader should work with source maps when the "devtool" option is enabled: warnings 1`] = `[]`; 463 | 464 | exports[`loader should work with string value: errors 1`] = `[]`; 465 | 466 | exports[`loader should work with string value: module 1`] = ` 467 | "var Foo = Foo || {}; 468 | var Bar = Bar || {}; 469 | var Baz = { 470 | nestedNumber: '12', 471 | nestedFunction: function test() {} 472 | }; 473 | var simple = function simple() {}; 474 | var simple_foo = [1, 2, 3, 4, 5]; 475 | 476 | Foo.Image = function(width, height, data){ 477 | this.width = width || 0; 478 | this.height = height || 0; 479 | this.data = data || []; 480 | }; 481 | 482 | Bar.test = [1, 2, 3, 4]; 483 | 484 | class MyClass { 485 | myFunction() { 486 | return 12; 487 | } 488 | } 489 | 490 | const single = 'single'; 491 | 492 | const myVariable = new MyClass(); 493 | 494 | /*** EXPORTS FROM exports-loader ***/ 495 | export { 496 | Foo 497 | }; 498 | " 499 | `; 500 | 501 | exports[`loader should work with string value: result 1`] = ` 502 | { 503 | "Foo": { 504 | "Image": [Function], 505 | }, 506 | } 507 | `; 508 | 509 | exports[`loader should work with string value: warnings 1`] = `[]`; 510 | 511 | exports[`loader should work with the "commonjs" module format for " " export list: errors 1`] = ` 512 | [ 513 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 514 | Error: Invalid " " value for export", 515 | ] 516 | `; 517 | 518 | exports[`loader should work with the "commonjs" module format for " " export list: warnings 1`] = `[]`; 519 | 520 | exports[`loader should work with the "commonjs" module format for " " export list: errors 1`] = ` 521 | [ 522 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 523 | Error: Invalid " " value for export", 524 | ] 525 | `; 526 | 527 | exports[`loader should work with the "commonjs" module format for " " export list: warnings 1`] = `[]`; 528 | 529 | exports[`loader should work with the "commonjs" module format for " Foo " export list: errors 1`] = `[]`; 530 | 531 | exports[`loader should work with the "commonjs" module format for " Foo " export list: module 1`] = ` 532 | "var Foo = Foo || {}; 533 | var Bar = Bar || {}; 534 | var Baz = { 535 | nestedNumber: '12', 536 | nestedFunction: function test() {} 537 | }; 538 | var simple = function simple() {}; 539 | var simple_foo = [1, 2, 3, 4, 5]; 540 | 541 | Foo.Image = function(width, height, data){ 542 | this.width = width || 0; 543 | this.height = height || 0; 544 | this.data = data || []; 545 | }; 546 | 547 | Bar.test = [1, 2, 3, 4]; 548 | 549 | class MyClass { 550 | myFunction() { 551 | return 12; 552 | } 553 | } 554 | 555 | const single = 'single'; 556 | 557 | const myVariable = new MyClass(); 558 | 559 | /*** EXPORTS FROM exports-loader ***/ 560 | module.exports = { 561 | Foo 562 | }; 563 | " 564 | `; 565 | 566 | exports[`loader should work with the "commonjs" module format for " Foo " export list: result 1`] = ` 567 | { 568 | "Foo": { 569 | "Image": [Function], 570 | }, 571 | } 572 | `; 573 | 574 | exports[`loader should work with the "commonjs" module format for " Foo " export list: warnings 1`] = `[]`; 575 | 576 | exports[`loader should work with the "commonjs" module format for " " export list: errors 1`] = ` 577 | [ 578 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 579 | Error: Invalid " " value for export", 580 | ] 581 | `; 582 | 583 | exports[`loader should work with the "commonjs" module format for " " export list: warnings 1`] = `[]`; 584 | 585 | exports[`loader should work with the "commonjs" module format for " " export list: errors 1`] = ` 586 | [ 587 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 588 | Error: Invalid " " value for export", 589 | ] 590 | `; 591 | 592 | exports[`loader should work with the "commonjs" module format for " " export list: warnings 1`] = `[]`; 593 | 594 | exports[`loader should work with the "commonjs" module format for "\`invalid\`" export list: errors 1`] = ` 595 | [ 596 | "ModuleParseError: Module parse failed: Unexpected token (30:2) 597 | File was processed with these loaders:", 598 | ] 599 | `; 600 | 601 | exports[`loader should work with the "commonjs" module format for "\`invalid\`" export list: warnings 1`] = `[]`; 602 | 603 | exports[`loader should work with the "commonjs" module format for "Foo" export list: errors 1`] = `[]`; 604 | 605 | exports[`loader should work with the "commonjs" module format for "Foo" export list: module 1`] = ` 606 | "var Foo = Foo || {}; 607 | var Bar = Bar || {}; 608 | var Baz = { 609 | nestedNumber: '12', 610 | nestedFunction: function test() {} 611 | }; 612 | var simple = function simple() {}; 613 | var simple_foo = [1, 2, 3, 4, 5]; 614 | 615 | Foo.Image = function(width, height, data){ 616 | this.width = width || 0; 617 | this.height = height || 0; 618 | this.data = data || []; 619 | }; 620 | 621 | Bar.test = [1, 2, 3, 4]; 622 | 623 | class MyClass { 624 | myFunction() { 625 | return 12; 626 | } 627 | } 628 | 629 | const single = 'single'; 630 | 631 | const myVariable = new MyClass(); 632 | 633 | /*** EXPORTS FROM exports-loader ***/ 634 | module.exports = { 635 | Foo 636 | }; 637 | " 638 | `; 639 | 640 | exports[`loader should work with the "commonjs" module format for "Foo" export list: result 1`] = ` 641 | { 642 | "Foo": { 643 | "Image": [Function], 644 | }, 645 | } 646 | `; 647 | 648 | exports[`loader should work with the "commonjs" module format for "Foo" export list: warnings 1`] = `[]`; 649 | 650 | exports[`loader should work with the "commonjs" module format for "default Foo" export list: errors 1`] = ` 651 | [ 652 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 653 | Error: The "commonjs" format can't be used with the "default" syntax export in "default Foo" value", 654 | ] 655 | `; 656 | 657 | exports[`loader should work with the "commonjs" module format for "default Foo" export list: warnings 1`] = `[]`; 658 | 659 | exports[`loader should work with the "commonjs" module format for "default" export list: errors 1`] = ` 660 | [ 661 | "ModuleParseError: Module parse failed: Unexpected keyword 'default' (30:2) 662 | File was processed with these loaders:", 663 | ] 664 | `; 665 | 666 | exports[`loader should work with the "commonjs" module format for "default" export list: warnings 1`] = `[]`; 667 | 668 | exports[`loader should work with the "commonjs" module format for "multiple Foo" export list: errors 1`] = ` 669 | [ 670 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 671 | Error: Invalid command "" in "multiple Foo" for exports. There must be only one separator: " ", or "|"", 672 | ] 673 | `; 674 | 675 | exports[`loader should work with the "commonjs" module format for "multiple Foo" export list: warnings 1`] = `[]`; 676 | 677 | exports[`loader should work with the "commonjs" module format for "multiple Foo Foo-Bar" export list: errors 1`] = `[]`; 678 | 679 | exports[`loader should work with the "commonjs" module format for "multiple Foo Foo-Bar" export list: module 1`] = ` 680 | "var Foo = Foo || {}; 681 | var Bar = Bar || {}; 682 | var Baz = { 683 | nestedNumber: '12', 684 | nestedFunction: function test() {} 685 | }; 686 | var simple = function simple() {}; 687 | var simple_foo = [1, 2, 3, 4, 5]; 688 | 689 | Foo.Image = function(width, height, data){ 690 | this.width = width || 0; 691 | this.height = height || 0; 692 | this.data = data || []; 693 | }; 694 | 695 | Bar.test = [1, 2, 3, 4]; 696 | 697 | class MyClass { 698 | myFunction() { 699 | return 12; 700 | } 701 | } 702 | 703 | const single = 'single'; 704 | 705 | const myVariable = new MyClass(); 706 | 707 | /*** EXPORTS FROM exports-loader ***/ 708 | module.exports = { 709 | "Foo-Bar": (Foo) 710 | }; 711 | " 712 | `; 713 | 714 | exports[`loader should work with the "commonjs" module format for "multiple Foo Foo-Bar" export list: result 1`] = ` 715 | { 716 | "Foo-Bar": { 717 | "Image": [Function], 718 | }, 719 | } 720 | `; 721 | 722 | exports[`loader should work with the "commonjs" module format for "multiple Foo Foo-Bar" export list: warnings 1`] = `[]`; 723 | 724 | exports[`loader should work with the "commonjs" module format for "multiple Foo FooA FooB" export list: errors 1`] = ` 725 | [ 726 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 727 | Error: Invalid "multiple Foo FooA FooB" value for export", 728 | ] 729 | `; 730 | 731 | exports[`loader should work with the "commonjs" module format for "multiple Foo FooA FooB" export list: warnings 1`] = `[]`; 732 | 733 | exports[`loader should work with the "commonjs" module format for "multiple Foo FooA" export list: errors 1`] = `[]`; 734 | 735 | exports[`loader should work with the "commonjs" module format for "multiple Foo FooA" export list: module 1`] = ` 736 | "var Foo = Foo || {}; 737 | var Bar = Bar || {}; 738 | var Baz = { 739 | nestedNumber: '12', 740 | nestedFunction: function test() {} 741 | }; 742 | var simple = function simple() {}; 743 | var simple_foo = [1, 2, 3, 4, 5]; 744 | 745 | Foo.Image = function(width, height, data){ 746 | this.width = width || 0; 747 | this.height = height || 0; 748 | this.data = data || []; 749 | }; 750 | 751 | Bar.test = [1, 2, 3, 4]; 752 | 753 | class MyClass { 754 | myFunction() { 755 | return 12; 756 | } 757 | } 758 | 759 | const single = 'single'; 760 | 761 | const myVariable = new MyClass(); 762 | 763 | /*** EXPORTS FROM exports-loader ***/ 764 | module.exports = { 765 | "FooA": (Foo) 766 | }; 767 | " 768 | `; 769 | 770 | exports[`loader should work with the "commonjs" module format for "multiple Foo FooA" export list: result 1`] = ` 771 | { 772 | "FooA": { 773 | "Image": [Function], 774 | }, 775 | } 776 | `; 777 | 778 | exports[`loader should work with the "commonjs" module format for "multiple Foo FooA" export list: warnings 1`] = `[]`; 779 | 780 | exports[`loader should work with the "commonjs" module format for "multiple Foo" export list: errors 1`] = `[]`; 781 | 782 | exports[`loader should work with the "commonjs" module format for "multiple Foo" export list: module 1`] = ` 783 | "var Foo = Foo || {}; 784 | var Bar = Bar || {}; 785 | var Baz = { 786 | nestedNumber: '12', 787 | nestedFunction: function test() {} 788 | }; 789 | var simple = function simple() {}; 790 | var simple_foo = [1, 2, 3, 4, 5]; 791 | 792 | Foo.Image = function(width, height, data){ 793 | this.width = width || 0; 794 | this.height = height || 0; 795 | this.data = data || []; 796 | }; 797 | 798 | Bar.test = [1, 2, 3, 4]; 799 | 800 | class MyClass { 801 | myFunction() { 802 | return 12; 803 | } 804 | } 805 | 806 | const single = 'single'; 807 | 808 | const myVariable = new MyClass(); 809 | 810 | /*** EXPORTS FROM exports-loader ***/ 811 | module.exports = { 812 | Foo 813 | }; 814 | " 815 | `; 816 | 817 | exports[`loader should work with the "commonjs" module format for "multiple Foo" export list: result 1`] = ` 818 | { 819 | "Foo": { 820 | "Image": [Function], 821 | }, 822 | } 823 | `; 824 | 825 | exports[`loader should work with the "commonjs" module format for "multiple Foo" export list: warnings 1`] = `[]`; 826 | 827 | exports[`loader should work with the "commonjs" module format for "multiple|Foo" export list: errors 1`] = `[]`; 828 | 829 | exports[`loader should work with the "commonjs" module format for "multiple|Foo" export list: module 1`] = ` 830 | "var Foo = Foo || {}; 831 | var Bar = Bar || {}; 832 | var Baz = { 833 | nestedNumber: '12', 834 | nestedFunction: function test() {} 835 | }; 836 | var simple = function simple() {}; 837 | var simple_foo = [1, 2, 3, 4, 5]; 838 | 839 | Foo.Image = function(width, height, data){ 840 | this.width = width || 0; 841 | this.height = height || 0; 842 | this.data = data || []; 843 | }; 844 | 845 | Bar.test = [1, 2, 3, 4]; 846 | 847 | class MyClass { 848 | myFunction() { 849 | return 12; 850 | } 851 | } 852 | 853 | const single = 'single'; 854 | 855 | const myVariable = new MyClass(); 856 | 857 | /*** EXPORTS FROM exports-loader ***/ 858 | module.exports = { 859 | Foo 860 | }; 861 | " 862 | `; 863 | 864 | exports[`loader should work with the "commonjs" module format for "multiple|Foo" export list: result 1`] = ` 865 | { 866 | "Foo": { 867 | "Image": [Function], 868 | }, 869 | } 870 | `; 871 | 872 | exports[`loader should work with the "commonjs" module format for "multiple|Foo" export list: warnings 1`] = `[]`; 873 | 874 | exports[`loader should work with the "commonjs" module format for "multiple|Foo|FooA" export list: errors 1`] = `[]`; 875 | 876 | exports[`loader should work with the "commonjs" module format for "multiple|Foo|FooA" export list: module 1`] = ` 877 | "var Foo = Foo || {}; 878 | var Bar = Bar || {}; 879 | var Baz = { 880 | nestedNumber: '12', 881 | nestedFunction: function test() {} 882 | }; 883 | var simple = function simple() {}; 884 | var simple_foo = [1, 2, 3, 4, 5]; 885 | 886 | Foo.Image = function(width, height, data){ 887 | this.width = width || 0; 888 | this.height = height || 0; 889 | this.data = data || []; 890 | }; 891 | 892 | Bar.test = [1, 2, 3, 4]; 893 | 894 | class MyClass { 895 | myFunction() { 896 | return 12; 897 | } 898 | } 899 | 900 | const single = 'single'; 901 | 902 | const myVariable = new MyClass(); 903 | 904 | /*** EXPORTS FROM exports-loader ***/ 905 | module.exports = { 906 | "FooA": (Foo) 907 | }; 908 | " 909 | `; 910 | 911 | exports[`loader should work with the "commonjs" module format for "multiple|Foo|FooA" export list: result 1`] = ` 912 | { 913 | "FooA": { 914 | "Image": [Function], 915 | }, 916 | } 917 | `; 918 | 919 | exports[`loader should work with the "commonjs" module format for "multiple|Foo|FooA" export list: warnings 1`] = `[]`; 920 | 921 | exports[`loader should work with the "commonjs" module format for "named Foo" export list: errors 1`] = ` 922 | [ 923 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 924 | Error: The "commonjs" format can't be used with the "named" syntax export in "named Foo" value", 925 | ] 926 | `; 927 | 928 | exports[`loader should work with the "commonjs" module format for "named Foo" export list: warnings 1`] = `[]`; 929 | 930 | exports[`loader should work with the "commonjs" module format for "single Foo FooA" export list: errors 1`] = ` 931 | [ 932 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 933 | Error: The "single" syntax can't have "FooA" alias in "single Foo FooA" value", 934 | ] 935 | `; 936 | 937 | exports[`loader should work with the "commonjs" module format for "single Foo FooA" export list: warnings 1`] = `[]`; 938 | 939 | exports[`loader should work with the "commonjs" module format for "single Foo" export list: errors 1`] = `[]`; 940 | 941 | exports[`loader should work with the "commonjs" module format for "single Foo" export list: module 1`] = ` 942 | "var Foo = Foo || {}; 943 | var Bar = Bar || {}; 944 | var Baz = { 945 | nestedNumber: '12', 946 | nestedFunction: function test() {} 947 | }; 948 | var simple = function simple() {}; 949 | var simple_foo = [1, 2, 3, 4, 5]; 950 | 951 | Foo.Image = function(width, height, data){ 952 | this.width = width || 0; 953 | this.height = height || 0; 954 | this.data = data || []; 955 | }; 956 | 957 | Bar.test = [1, 2, 3, 4]; 958 | 959 | class MyClass { 960 | myFunction() { 961 | return 12; 962 | } 963 | } 964 | 965 | const single = 'single'; 966 | 967 | const myVariable = new MyClass(); 968 | 969 | /*** EXPORTS FROM exports-loader ***/ 970 | module.exports = Foo; 971 | " 972 | `; 973 | 974 | exports[`loader should work with the "commonjs" module format for "single Foo" export list: result 1`] = ` 975 | { 976 | "Image": [Function], 977 | } 978 | `; 979 | 980 | exports[`loader should work with the "commonjs" module format for "single Foo" export list: warnings 1`] = `[]`; 981 | 982 | exports[`loader should work with the "commonjs" module format for "single single" export list: errors 1`] = `[]`; 983 | 984 | exports[`loader should work with the "commonjs" module format for "single single" export list: module 1`] = ` 985 | "var Foo = Foo || {}; 986 | var Bar = Bar || {}; 987 | var Baz = { 988 | nestedNumber: '12', 989 | nestedFunction: function test() {} 990 | }; 991 | var simple = function simple() {}; 992 | var simple_foo = [1, 2, 3, 4, 5]; 993 | 994 | Foo.Image = function(width, height, data){ 995 | this.width = width || 0; 996 | this.height = height || 0; 997 | this.data = data || []; 998 | }; 999 | 1000 | Bar.test = [1, 2, 3, 4]; 1001 | 1002 | class MyClass { 1003 | myFunction() { 1004 | return 12; 1005 | } 1006 | } 1007 | 1008 | const single = 'single'; 1009 | 1010 | const myVariable = new MyClass(); 1011 | 1012 | /*** EXPORTS FROM exports-loader ***/ 1013 | module.exports = single; 1014 | " 1015 | `; 1016 | 1017 | exports[`loader should work with the "commonjs" module format for "single single" export list: result 1`] = `"single"`; 1018 | 1019 | exports[`loader should work with the "commonjs" module format for "single single" export list: warnings 1`] = `[]`; 1020 | 1021 | exports[`loader should work with the "commonjs" module format for "unknown Foo" export list: errors 1`] = ` 1022 | [ 1023 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1024 | Error: Unknown "unknown" syntax export in "unknown Foo" value", 1025 | ] 1026 | `; 1027 | 1028 | exports[`loader should work with the "commonjs" module format for "unknown Foo" export list: warnings 1`] = `[]`; 1029 | 1030 | exports[`loader should work with the "commonjs" module format for ["Foo","Bar"] export list: errors 1`] = `[]`; 1031 | 1032 | exports[`loader should work with the "commonjs" module format for ["Foo","Bar"] export list: module 1`] = ` 1033 | "var Foo = Foo || {}; 1034 | var Bar = Bar || {}; 1035 | var Baz = { 1036 | nestedNumber: '12', 1037 | nestedFunction: function test() {} 1038 | }; 1039 | var simple = function simple() {}; 1040 | var simple_foo = [1, 2, 3, 4, 5]; 1041 | 1042 | Foo.Image = function(width, height, data){ 1043 | this.width = width || 0; 1044 | this.height = height || 0; 1045 | this.data = data || []; 1046 | }; 1047 | 1048 | Bar.test = [1, 2, 3, 4]; 1049 | 1050 | class MyClass { 1051 | myFunction() { 1052 | return 12; 1053 | } 1054 | } 1055 | 1056 | const single = 'single'; 1057 | 1058 | const myVariable = new MyClass(); 1059 | 1060 | /*** EXPORTS FROM exports-loader ***/ 1061 | module.exports = { 1062 | Foo, 1063 | Bar 1064 | }; 1065 | " 1066 | `; 1067 | 1068 | exports[`loader should work with the "commonjs" module format for ["Foo","Bar"] export list: result 1`] = ` 1069 | { 1070 | "Bar": { 1071 | "test": [ 1072 | 1, 1073 | 2, 1074 | 3, 1075 | 4, 1076 | ], 1077 | }, 1078 | "Foo": { 1079 | "Image": [Function], 1080 | }, 1081 | } 1082 | `; 1083 | 1084 | exports[`loader should work with the "commonjs" module format for ["Foo","Bar"] export list: warnings 1`] = `[]`; 1085 | 1086 | exports[`loader should work with the "commonjs" module format for ["multiple Foo Bar","multiple Bar"] export list: errors 1`] = ` 1087 | [ 1088 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1089 | Error: Duplicate "Bar" (as "alias"), "Bar" (as "name") identifiers found in "", 1090 | ] 1091 | `; 1092 | 1093 | exports[`loader should work with the "commonjs" module format for ["multiple Foo Bar","multiple Bar"] export list: warnings 1`] = `[]`; 1094 | 1095 | exports[`loader should work with the "commonjs" module format for ["multiple Foo Baz","multiple Bar Baz"] export list: errors 1`] = ` 1096 | [ 1097 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1098 | Error: Duplicate "Baz" (as "alias"), "Baz" (as "alias") identifiers found in "", 1099 | ] 1100 | `; 1101 | 1102 | exports[`loader should work with the "commonjs" module format for ["multiple Foo Baz","multiple Bar Baz"] export list: warnings 1`] = `[]`; 1103 | 1104 | exports[`loader should work with the "commonjs" module format for ["multiple Foo FooA","multiple Bar BarA"] export list: errors 1`] = `[]`; 1105 | 1106 | exports[`loader should work with the "commonjs" module format for ["multiple Foo FooA","multiple Bar BarA"] export list: module 1`] = ` 1107 | "var Foo = Foo || {}; 1108 | var Bar = Bar || {}; 1109 | var Baz = { 1110 | nestedNumber: '12', 1111 | nestedFunction: function test() {} 1112 | }; 1113 | var simple = function simple() {}; 1114 | var simple_foo = [1, 2, 3, 4, 5]; 1115 | 1116 | Foo.Image = function(width, height, data){ 1117 | this.width = width || 0; 1118 | this.height = height || 0; 1119 | this.data = data || []; 1120 | }; 1121 | 1122 | Bar.test = [1, 2, 3, 4]; 1123 | 1124 | class MyClass { 1125 | myFunction() { 1126 | return 12; 1127 | } 1128 | } 1129 | 1130 | const single = 'single'; 1131 | 1132 | const myVariable = new MyClass(); 1133 | 1134 | /*** EXPORTS FROM exports-loader ***/ 1135 | module.exports = { 1136 | "FooA": (Foo), 1137 | "BarA": (Bar) 1138 | }; 1139 | " 1140 | `; 1141 | 1142 | exports[`loader should work with the "commonjs" module format for ["multiple Foo FooA","multiple Bar BarA"] export list: result 1`] = ` 1143 | { 1144 | "BarA": { 1145 | "test": [ 1146 | 1, 1147 | 2, 1148 | 3, 1149 | 4, 1150 | ], 1151 | }, 1152 | "FooA": { 1153 | "Image": [Function], 1154 | }, 1155 | } 1156 | `; 1157 | 1158 | exports[`loader should work with the "commonjs" module format for ["multiple Foo FooA","multiple Bar BarA"] export list: warnings 1`] = `[]`; 1159 | 1160 | exports[`loader should work with the "commonjs" module format for ["multiple Foo","multiple Bar Foo"] export list: errors 1`] = ` 1161 | [ 1162 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1163 | Error: Duplicate "Foo" (as "name"), "Foo" (as "alias") identifiers found in "", 1164 | ] 1165 | `; 1166 | 1167 | exports[`loader should work with the "commonjs" module format for ["multiple Foo","multiple Bar Foo"] export list: warnings 1`] = `[]`; 1168 | 1169 | exports[`loader should work with the "commonjs" module format for ["multiple Foo","multiple Bar"] export list: errors 1`] = `[]`; 1170 | 1171 | exports[`loader should work with the "commonjs" module format for ["multiple Foo","multiple Bar"] export list: module 1`] = ` 1172 | "var Foo = Foo || {}; 1173 | var Bar = Bar || {}; 1174 | var Baz = { 1175 | nestedNumber: '12', 1176 | nestedFunction: function test() {} 1177 | }; 1178 | var simple = function simple() {}; 1179 | var simple_foo = [1, 2, 3, 4, 5]; 1180 | 1181 | Foo.Image = function(width, height, data){ 1182 | this.width = width || 0; 1183 | this.height = height || 0; 1184 | this.data = data || []; 1185 | }; 1186 | 1187 | Bar.test = [1, 2, 3, 4]; 1188 | 1189 | class MyClass { 1190 | myFunction() { 1191 | return 12; 1192 | } 1193 | } 1194 | 1195 | const single = 'single'; 1196 | 1197 | const myVariable = new MyClass(); 1198 | 1199 | /*** EXPORTS FROM exports-loader ***/ 1200 | module.exports = { 1201 | Foo, 1202 | Bar 1203 | }; 1204 | " 1205 | `; 1206 | 1207 | exports[`loader should work with the "commonjs" module format for ["multiple Foo","multiple Bar"] export list: result 1`] = ` 1208 | { 1209 | "Bar": { 1210 | "test": [ 1211 | 1, 1212 | 2, 1213 | 3, 1214 | 4, 1215 | ], 1216 | }, 1217 | "Foo": { 1218 | "Image": [Function], 1219 | }, 1220 | } 1221 | `; 1222 | 1223 | exports[`loader should work with the "commonjs" module format for ["multiple Foo","multiple Bar"] export list: warnings 1`] = `[]`; 1224 | 1225 | exports[`loader should work with the "commonjs" module format for ["multiple Foo","multiple Foo"] export list: errors 1`] = ` 1226 | [ 1227 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1228 | Error: Duplicate "Foo" (as "name"), "Foo" (as "name") identifiers found in "", 1229 | ] 1230 | `; 1231 | 1232 | exports[`loader should work with the "commonjs" module format for ["multiple Foo","multiple Foo"] export list: warnings 1`] = `[]`; 1233 | 1234 | exports[`loader should work with the "commonjs" module format for ["multiple myVariable.myFunction foo.bar","multiple Bar foo.bar"] export list: errors 1`] = ` 1235 | [ 1236 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1237 | Error: Duplicate "foo.bar" (as "alias"), "foo.bar" (as "alias") identifiers found in "", 1238 | ] 1239 | `; 1240 | 1241 | exports[`loader should work with the "commonjs" module format for ["multiple myVariable.myFunction foo.bar","multiple Bar foo.bar"] export list: warnings 1`] = `[]`; 1242 | 1243 | exports[`loader should work with the "commonjs" module format for ["multiple myVariable.myFunction myFunction","multiple Bar BarA"] export list: errors 1`] = `[]`; 1244 | 1245 | exports[`loader should work with the "commonjs" module format for ["multiple myVariable.myFunction myFunction","multiple Bar BarA"] export list: module 1`] = ` 1246 | "var Foo = Foo || {}; 1247 | var Bar = Bar || {}; 1248 | var Baz = { 1249 | nestedNumber: '12', 1250 | nestedFunction: function test() {} 1251 | }; 1252 | var simple = function simple() {}; 1253 | var simple_foo = [1, 2, 3, 4, 5]; 1254 | 1255 | Foo.Image = function(width, height, data){ 1256 | this.width = width || 0; 1257 | this.height = height || 0; 1258 | this.data = data || []; 1259 | }; 1260 | 1261 | Bar.test = [1, 2, 3, 4]; 1262 | 1263 | class MyClass { 1264 | myFunction() { 1265 | return 12; 1266 | } 1267 | } 1268 | 1269 | const single = 'single'; 1270 | 1271 | const myVariable = new MyClass(); 1272 | 1273 | /*** EXPORTS FROM exports-loader ***/ 1274 | module.exports = { 1275 | "myFunction": (myVariable.myFunction), 1276 | "BarA": (Bar) 1277 | }; 1278 | " 1279 | `; 1280 | 1281 | exports[`loader should work with the "commonjs" module format for ["multiple myVariable.myFunction myFunction","multiple Bar BarA"] export list: result 1`] = ` 1282 | { 1283 | "BarA": { 1284 | "test": [ 1285 | 1, 1286 | 2, 1287 | 3, 1288 | 4, 1289 | ], 1290 | }, 1291 | "myFunction": [Function], 1292 | } 1293 | `; 1294 | 1295 | exports[`loader should work with the "commonjs" module format for ["multiple myVariable.myFunction myFunction","multiple Bar BarA"] export list: warnings 1`] = `[]`; 1296 | 1297 | exports[`loader should work with the "commonjs" module format for ["multiple myVariable.myFunction","multiple Bar myVariable.myFunction"] export list: errors 1`] = ` 1298 | [ 1299 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1300 | Error: Duplicate "myVariable.myFunction" (as "name"), "myVariable.myFunction" (as "alias") identifiers found in "", 1301 | ] 1302 | `; 1303 | 1304 | exports[`loader should work with the "commonjs" module format for ["multiple myVariable.myFunction","multiple Bar myVariable.myFunction"] export list: warnings 1`] = `[]`; 1305 | 1306 | exports[`loader should work with the "commonjs" module format for ["single Foo","single Bar"] export list: errors 1`] = ` 1307 | [ 1308 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1309 | Error: The "commonjs" format can't have multiple "single" exports in "", 1310 | ] 1311 | `; 1312 | 1313 | exports[`loader should work with the "commonjs" module format for ["single Foo","single Bar"] export list: warnings 1`] = `[]`; 1314 | 1315 | exports[`loader should work with the "commonjs" module format for {"syntax":"default","name":"Foo"} export list: errors 1`] = ` 1316 | [ 1317 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1318 | Error: The "commonjs" format can't be used with the "default" syntax export in "", 1319 | ] 1320 | `; 1321 | 1322 | exports[`loader should work with the "commonjs" module format for {"syntax":"default","name":"Foo"} export list: warnings 1`] = `[]`; 1323 | 1324 | exports[`loader should work with the "commonjs" module format for {"syntax":"single","name":"Foo","alias":"FooA"} export list: errors 1`] = ` 1325 | [ 1326 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1327 | Error: The "single" syntax can't have "FooA" alias in "", 1328 | ] 1329 | `; 1330 | 1331 | exports[`loader should work with the "commonjs" module format for {"syntax":"single","name":"Foo","alias":"FooA"} export list: warnings 1`] = `[]`; 1332 | 1333 | exports[`loader should work with the "commonjs" module format for {"syntax":"unknown","name":"Foo"} export list: errors 1`] = ` 1334 | [ 1335 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1336 | ValidationError: Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema.", 1337 | ] 1338 | `; 1339 | 1340 | exports[`loader should work with the "commonjs" module format for {"syntax":"unknown","name":"Foo"} export list: warnings 1`] = `[]`; 1341 | 1342 | exports[`loader should work with the "module" module format for " " export list: errors 1`] = ` 1343 | [ 1344 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1345 | Error: Invalid " " value for export", 1346 | ] 1347 | `; 1348 | 1349 | exports[`loader should work with the "module" module format for " " export list: warnings 1`] = `[]`; 1350 | 1351 | exports[`loader should work with the "module" module format for " " export list: errors 1`] = ` 1352 | [ 1353 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1354 | Error: Invalid " " value for export", 1355 | ] 1356 | `; 1357 | 1358 | exports[`loader should work with the "module" module format for " " export list: warnings 1`] = `[]`; 1359 | 1360 | exports[`loader should work with the "module" module format for " Foo " export list: errors 1`] = `[]`; 1361 | 1362 | exports[`loader should work with the "module" module format for " Foo " export list: module 1`] = ` 1363 | "var Foo = Foo || {}; 1364 | var Bar = Bar || {}; 1365 | var Baz = { 1366 | nestedNumber: '12', 1367 | nestedFunction: function test() {} 1368 | }; 1369 | var simple = function simple() {}; 1370 | var simple_foo = [1, 2, 3, 4, 5]; 1371 | 1372 | Foo.Image = function(width, height, data){ 1373 | this.width = width || 0; 1374 | this.height = height || 0; 1375 | this.data = data || []; 1376 | }; 1377 | 1378 | Bar.test = [1, 2, 3, 4]; 1379 | 1380 | class MyClass { 1381 | myFunction() { 1382 | return 12; 1383 | } 1384 | } 1385 | 1386 | const single = 'single'; 1387 | 1388 | const myVariable = new MyClass(); 1389 | 1390 | /*** EXPORTS FROM exports-loader ***/ 1391 | export { 1392 | Foo 1393 | }; 1394 | " 1395 | `; 1396 | 1397 | exports[`loader should work with the "module" module format for " Foo " export list: result 1`] = ` 1398 | { 1399 | "Foo": { 1400 | "Image": [Function], 1401 | }, 1402 | } 1403 | `; 1404 | 1405 | exports[`loader should work with the "module" module format for " Foo " export list: warnings 1`] = `[]`; 1406 | 1407 | exports[`loader should work with the "module" module format for " " export list: errors 1`] = ` 1408 | [ 1409 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1410 | Error: Invalid " " value for export", 1411 | ] 1412 | `; 1413 | 1414 | exports[`loader should work with the "module" module format for " " export list: warnings 1`] = `[]`; 1415 | 1416 | exports[`loader should work with the "module" module format for " " export list: errors 1`] = ` 1417 | [ 1418 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1419 | Error: Invalid " " value for export", 1420 | ] 1421 | `; 1422 | 1423 | exports[`loader should work with the "module" module format for " " export list: warnings 1`] = `[]`; 1424 | 1425 | exports[`loader should work with the "module" module format for "\`invalid\`" export list: errors 1`] = ` 1426 | [ 1427 | "ModuleParseError: Module parse failed: Unexpected token (30:2) 1428 | File was processed with these loaders:", 1429 | ] 1430 | `; 1431 | 1432 | exports[`loader should work with the "module" module format for "\`invalid\`" export list: warnings 1`] = `[]`; 1433 | 1434 | exports[`loader should work with the "module" module format for "Foo" export list: errors 1`] = `[]`; 1435 | 1436 | exports[`loader should work with the "module" module format for "Foo" export list: module 1`] = ` 1437 | "var Foo = Foo || {}; 1438 | var Bar = Bar || {}; 1439 | var Baz = { 1440 | nestedNumber: '12', 1441 | nestedFunction: function test() {} 1442 | }; 1443 | var simple = function simple() {}; 1444 | var simple_foo = [1, 2, 3, 4, 5]; 1445 | 1446 | Foo.Image = function(width, height, data){ 1447 | this.width = width || 0; 1448 | this.height = height || 0; 1449 | this.data = data || []; 1450 | }; 1451 | 1452 | Bar.test = [1, 2, 3, 4]; 1453 | 1454 | class MyClass { 1455 | myFunction() { 1456 | return 12; 1457 | } 1458 | } 1459 | 1460 | const single = 'single'; 1461 | 1462 | const myVariable = new MyClass(); 1463 | 1464 | /*** EXPORTS FROM exports-loader ***/ 1465 | export { 1466 | Foo 1467 | }; 1468 | " 1469 | `; 1470 | 1471 | exports[`loader should work with the "module" module format for "Foo" export list: result 1`] = ` 1472 | { 1473 | "Foo": { 1474 | "Image": [Function], 1475 | }, 1476 | } 1477 | `; 1478 | 1479 | exports[`loader should work with the "module" module format for "Foo" export list: warnings 1`] = `[]`; 1480 | 1481 | exports[`loader should work with the "module" module format for "default Foo FooA" export list: errors 1`] = ` 1482 | [ 1483 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1484 | Error: The "default" syntax can't have "FooA" alias in "default Foo FooA" value", 1485 | ] 1486 | `; 1487 | 1488 | exports[`loader should work with the "module" module format for "default Foo FooA" export list: warnings 1`] = `[]`; 1489 | 1490 | exports[`loader should work with the "module" module format for "default Foo" export list: errors 1`] = `[]`; 1491 | 1492 | exports[`loader should work with the "module" module format for "default Foo" export list: module 1`] = ` 1493 | "var Foo = Foo || {}; 1494 | var Bar = Bar || {}; 1495 | var Baz = { 1496 | nestedNumber: '12', 1497 | nestedFunction: function test() {} 1498 | }; 1499 | var simple = function simple() {}; 1500 | var simple_foo = [1, 2, 3, 4, 5]; 1501 | 1502 | Foo.Image = function(width, height, data){ 1503 | this.width = width || 0; 1504 | this.height = height || 0; 1505 | this.data = data || []; 1506 | }; 1507 | 1508 | Bar.test = [1, 2, 3, 4]; 1509 | 1510 | class MyClass { 1511 | myFunction() { 1512 | return 12; 1513 | } 1514 | } 1515 | 1516 | const single = 'single'; 1517 | 1518 | const myVariable = new MyClass(); 1519 | 1520 | /*** EXPORTS FROM exports-loader ***/ 1521 | export default Foo; 1522 | " 1523 | `; 1524 | 1525 | exports[`loader should work with the "module" module format for "default Foo" export list: result 1`] = ` 1526 | { 1527 | "default": { 1528 | "Image": [Function], 1529 | }, 1530 | } 1531 | `; 1532 | 1533 | exports[`loader should work with the "module" module format for "default Foo" export list: warnings 1`] = `[]`; 1534 | 1535 | exports[`loader should work with the "module" module format for "default default" export list: errors 1`] = ` 1536 | [ 1537 | "ModuleParseError: Module parse failed: Unexpected token (29:15) 1538 | File was processed with these loaders:", 1539 | ] 1540 | `; 1541 | 1542 | exports[`loader should work with the "module" module format for "default default" export list: warnings 1`] = `[]`; 1543 | 1544 | exports[`loader should work with the "module" module format for "default" export list: errors 1`] = ` 1545 | [ 1546 | "ModuleParseError: Module parse failed: Unexpected keyword 'default' (30:2) 1547 | File was processed with these loaders:", 1548 | ] 1549 | `; 1550 | 1551 | exports[`loader should work with the "module" module format for "default" export list: warnings 1`] = `[]`; 1552 | 1553 | exports[`loader should work with the "module" module format for "multiple Foo" export list: errors 1`] = ` 1554 | [ 1555 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1556 | Error: The "module" format can't be used with the "multiple" syntax export in "multiple Foo" value", 1557 | ] 1558 | `; 1559 | 1560 | exports[`loader should work with the "module" module format for "multiple Foo" export list: warnings 1`] = `[]`; 1561 | 1562 | exports[`loader should work with the "module" module format for "named Foo FooA FooB" export list: errors 1`] = ` 1563 | [ 1564 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1565 | Error: Invalid "named Foo FooA FooB" value for export", 1566 | ] 1567 | `; 1568 | 1569 | exports[`loader should work with the "module" module format for "named Foo FooA FooB" export list: warnings 1`] = `[]`; 1570 | 1571 | exports[`loader should work with the "module" module format for "named Foo FooA" export list: errors 1`] = `[]`; 1572 | 1573 | exports[`loader should work with the "module" module format for "named Foo FooA" export list: module 1`] = ` 1574 | "var Foo = Foo || {}; 1575 | var Bar = Bar || {}; 1576 | var Baz = { 1577 | nestedNumber: '12', 1578 | nestedFunction: function test() {} 1579 | }; 1580 | var simple = function simple() {}; 1581 | var simple_foo = [1, 2, 3, 4, 5]; 1582 | 1583 | Foo.Image = function(width, height, data){ 1584 | this.width = width || 0; 1585 | this.height = height || 0; 1586 | this.data = data || []; 1587 | }; 1588 | 1589 | Bar.test = [1, 2, 3, 4]; 1590 | 1591 | class MyClass { 1592 | myFunction() { 1593 | return 12; 1594 | } 1595 | } 1596 | 1597 | const single = 'single'; 1598 | 1599 | const myVariable = new MyClass(); 1600 | 1601 | /*** EXPORTS FROM exports-loader ***/ 1602 | export { 1603 | Foo as FooA 1604 | }; 1605 | " 1606 | `; 1607 | 1608 | exports[`loader should work with the "module" module format for "named Foo FooA" export list: result 1`] = ` 1609 | { 1610 | "FooA": { 1611 | "Image": [Function], 1612 | }, 1613 | } 1614 | `; 1615 | 1616 | exports[`loader should work with the "module" module format for "named Foo FooA" export list: warnings 1`] = `[]`; 1617 | 1618 | exports[`loader should work with the "module" module format for "named Foo" export list: errors 1`] = `[]`; 1619 | 1620 | exports[`loader should work with the "module" module format for "named Foo" export list: module 1`] = ` 1621 | "var Foo = Foo || {}; 1622 | var Bar = Bar || {}; 1623 | var Baz = { 1624 | nestedNumber: '12', 1625 | nestedFunction: function test() {} 1626 | }; 1627 | var simple = function simple() {}; 1628 | var simple_foo = [1, 2, 3, 4, 5]; 1629 | 1630 | Foo.Image = function(width, height, data){ 1631 | this.width = width || 0; 1632 | this.height = height || 0; 1633 | this.data = data || []; 1634 | }; 1635 | 1636 | Bar.test = [1, 2, 3, 4]; 1637 | 1638 | class MyClass { 1639 | myFunction() { 1640 | return 12; 1641 | } 1642 | } 1643 | 1644 | const single = 'single'; 1645 | 1646 | const myVariable = new MyClass(); 1647 | 1648 | /*** EXPORTS FROM exports-loader ***/ 1649 | export { 1650 | Foo 1651 | }; 1652 | " 1653 | `; 1654 | 1655 | exports[`loader should work with the "module" module format for "named Foo" export list: result 1`] = ` 1656 | { 1657 | "Foo": { 1658 | "Image": [Function], 1659 | }, 1660 | } 1661 | `; 1662 | 1663 | exports[`loader should work with the "module" module format for "named Foo" export list: warnings 1`] = `[]`; 1664 | 1665 | exports[`loader should work with the "module" module format for "named|Foo" export list: errors 1`] = `[]`; 1666 | 1667 | exports[`loader should work with the "module" module format for "named|Foo" export list: module 1`] = ` 1668 | "var Foo = Foo || {}; 1669 | var Bar = Bar || {}; 1670 | var Baz = { 1671 | nestedNumber: '12', 1672 | nestedFunction: function test() {} 1673 | }; 1674 | var simple = function simple() {}; 1675 | var simple_foo = [1, 2, 3, 4, 5]; 1676 | 1677 | Foo.Image = function(width, height, data){ 1678 | this.width = width || 0; 1679 | this.height = height || 0; 1680 | this.data = data || []; 1681 | }; 1682 | 1683 | Bar.test = [1, 2, 3, 4]; 1684 | 1685 | class MyClass { 1686 | myFunction() { 1687 | return 12; 1688 | } 1689 | } 1690 | 1691 | const single = 'single'; 1692 | 1693 | const myVariable = new MyClass(); 1694 | 1695 | /*** EXPORTS FROM exports-loader ***/ 1696 | export { 1697 | Foo 1698 | }; 1699 | " 1700 | `; 1701 | 1702 | exports[`loader should work with the "module" module format for "named|Foo" export list: result 1`] = ` 1703 | { 1704 | "Foo": { 1705 | "Image": [Function], 1706 | }, 1707 | } 1708 | `; 1709 | 1710 | exports[`loader should work with the "module" module format for "named|Foo" export list: warnings 1`] = `[]`; 1711 | 1712 | exports[`loader should work with the "module" module format for "named|Foo|FooA" export list: errors 1`] = `[]`; 1713 | 1714 | exports[`loader should work with the "module" module format for "named|Foo|FooA" export list: module 1`] = ` 1715 | "var Foo = Foo || {}; 1716 | var Bar = Bar || {}; 1717 | var Baz = { 1718 | nestedNumber: '12', 1719 | nestedFunction: function test() {} 1720 | }; 1721 | var simple = function simple() {}; 1722 | var simple_foo = [1, 2, 3, 4, 5]; 1723 | 1724 | Foo.Image = function(width, height, data){ 1725 | this.width = width || 0; 1726 | this.height = height || 0; 1727 | this.data = data || []; 1728 | }; 1729 | 1730 | Bar.test = [1, 2, 3, 4]; 1731 | 1732 | class MyClass { 1733 | myFunction() { 1734 | return 12; 1735 | } 1736 | } 1737 | 1738 | const single = 'single'; 1739 | 1740 | const myVariable = new MyClass(); 1741 | 1742 | /*** EXPORTS FROM exports-loader ***/ 1743 | export { 1744 | Foo as FooA 1745 | }; 1746 | " 1747 | `; 1748 | 1749 | exports[`loader should work with the "module" module format for "named|Foo|FooA" export list: result 1`] = ` 1750 | { 1751 | "FooA": { 1752 | "Image": [Function], 1753 | }, 1754 | } 1755 | `; 1756 | 1757 | exports[`loader should work with the "module" module format for "named|Foo|FooA" export list: warnings 1`] = `[]`; 1758 | 1759 | exports[`loader should work with the "module" module format for "single Foo" export list: errors 1`] = ` 1760 | [ 1761 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1762 | Error: The "module" format can't be used with the "single" syntax export in "single Foo" value", 1763 | ] 1764 | `; 1765 | 1766 | exports[`loader should work with the "module" module format for "single Foo" export list: warnings 1`] = `[]`; 1767 | 1768 | exports[`loader should work with the "module" module format for "unknown Foo" export list: errors 1`] = ` 1769 | [ 1770 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1771 | Error: Unknown "unknown" syntax export in "unknown Foo" value", 1772 | ] 1773 | `; 1774 | 1775 | exports[`loader should work with the "module" module format for "unknown Foo" export list: warnings 1`] = `[]`; 1776 | 1777 | exports[`loader should work with the "module" module format for ["Foo","Bar"] export list: errors 1`] = `[]`; 1778 | 1779 | exports[`loader should work with the "module" module format for ["Foo","Bar"] export list: module 1`] = ` 1780 | "var Foo = Foo || {}; 1781 | var Bar = Bar || {}; 1782 | var Baz = { 1783 | nestedNumber: '12', 1784 | nestedFunction: function test() {} 1785 | }; 1786 | var simple = function simple() {}; 1787 | var simple_foo = [1, 2, 3, 4, 5]; 1788 | 1789 | Foo.Image = function(width, height, data){ 1790 | this.width = width || 0; 1791 | this.height = height || 0; 1792 | this.data = data || []; 1793 | }; 1794 | 1795 | Bar.test = [1, 2, 3, 4]; 1796 | 1797 | class MyClass { 1798 | myFunction() { 1799 | return 12; 1800 | } 1801 | } 1802 | 1803 | const single = 'single'; 1804 | 1805 | const myVariable = new MyClass(); 1806 | 1807 | /*** EXPORTS FROM exports-loader ***/ 1808 | export { 1809 | Foo, 1810 | Bar 1811 | }; 1812 | " 1813 | `; 1814 | 1815 | exports[`loader should work with the "module" module format for ["Foo","Bar"] export list: result 1`] = ` 1816 | { 1817 | "Bar": { 1818 | "test": [ 1819 | 1, 1820 | 2, 1821 | 3, 1822 | 4, 1823 | ], 1824 | }, 1825 | "Foo": { 1826 | "Image": [Function], 1827 | }, 1828 | } 1829 | `; 1830 | 1831 | exports[`loader should work with the "module" module format for ["Foo","Bar"] export list: warnings 1`] = `[]`; 1832 | 1833 | exports[`loader should work with the "module" module format for ["default Foo","default Bar"] export list: errors 1`] = ` 1834 | [ 1835 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 1836 | Error: The "module" format can't have multiple "default" exports in "", 1837 | ] 1838 | `; 1839 | 1840 | exports[`loader should work with the "module" module format for ["default Foo","default Bar"] export list: warnings 1`] = `[]`; 1841 | 1842 | exports[`loader should work with the "module" module format for ["default Foo","named Bar BarA","named Baz"] export list: errors 1`] = `[]`; 1843 | 1844 | exports[`loader should work with the "module" module format for ["default Foo","named Bar BarA","named Baz"] export list: module 1`] = ` 1845 | "var Foo = Foo || {}; 1846 | var Bar = Bar || {}; 1847 | var Baz = { 1848 | nestedNumber: '12', 1849 | nestedFunction: function test() {} 1850 | }; 1851 | var simple = function simple() {}; 1852 | var simple_foo = [1, 2, 3, 4, 5]; 1853 | 1854 | Foo.Image = function(width, height, data){ 1855 | this.width = width || 0; 1856 | this.height = height || 0; 1857 | this.data = data || []; 1858 | }; 1859 | 1860 | Bar.test = [1, 2, 3, 4]; 1861 | 1862 | class MyClass { 1863 | myFunction() { 1864 | return 12; 1865 | } 1866 | } 1867 | 1868 | const single = 'single'; 1869 | 1870 | const myVariable = new MyClass(); 1871 | 1872 | /*** EXPORTS FROM exports-loader ***/ 1873 | export default Foo; 1874 | export { 1875 | Bar as BarA, 1876 | Baz 1877 | }; 1878 | " 1879 | `; 1880 | 1881 | exports[`loader should work with the "module" module format for ["default Foo","named Bar BarA","named Baz"] export list: result 1`] = ` 1882 | { 1883 | "BarA": { 1884 | "test": [ 1885 | 1, 1886 | 2, 1887 | 3, 1888 | 4, 1889 | ], 1890 | }, 1891 | "Baz": { 1892 | "nestedFunction": [Function], 1893 | "nestedNumber": "12", 1894 | }, 1895 | "default": { 1896 | "Image": [Function], 1897 | }, 1898 | } 1899 | `; 1900 | 1901 | exports[`loader should work with the "module" module format for ["default Foo","named Bar BarA","named Baz"] export list: warnings 1`] = `[]`; 1902 | 1903 | exports[`loader should work with the "module" module format for ["default Foo","named Bar BarA"] export list: errors 1`] = `[]`; 1904 | 1905 | exports[`loader should work with the "module" module format for ["default Foo","named Bar BarA"] export list: module 1`] = ` 1906 | "var Foo = Foo || {}; 1907 | var Bar = Bar || {}; 1908 | var Baz = { 1909 | nestedNumber: '12', 1910 | nestedFunction: function test() {} 1911 | }; 1912 | var simple = function simple() {}; 1913 | var simple_foo = [1, 2, 3, 4, 5]; 1914 | 1915 | Foo.Image = function(width, height, data){ 1916 | this.width = width || 0; 1917 | this.height = height || 0; 1918 | this.data = data || []; 1919 | }; 1920 | 1921 | Bar.test = [1, 2, 3, 4]; 1922 | 1923 | class MyClass { 1924 | myFunction() { 1925 | return 12; 1926 | } 1927 | } 1928 | 1929 | const single = 'single'; 1930 | 1931 | const myVariable = new MyClass(); 1932 | 1933 | /*** EXPORTS FROM exports-loader ***/ 1934 | export default Foo; 1935 | export { 1936 | Bar as BarA 1937 | }; 1938 | " 1939 | `; 1940 | 1941 | exports[`loader should work with the "module" module format for ["default Foo","named Bar BarA"] export list: result 1`] = ` 1942 | { 1943 | "BarA": { 1944 | "test": [ 1945 | 1, 1946 | 2, 1947 | 3, 1948 | 4, 1949 | ], 1950 | }, 1951 | "default": { 1952 | "Image": [Function], 1953 | }, 1954 | } 1955 | `; 1956 | 1957 | exports[`loader should work with the "module" module format for ["default Foo","named Bar BarA"] export list: warnings 1`] = `[]`; 1958 | 1959 | exports[`loader should work with the "module" module format for ["default Foo","named Bar"] export list: errors 1`] = `[]`; 1960 | 1961 | exports[`loader should work with the "module" module format for ["default Foo","named Bar"] export list: module 1`] = ` 1962 | "var Foo = Foo || {}; 1963 | var Bar = Bar || {}; 1964 | var Baz = { 1965 | nestedNumber: '12', 1966 | nestedFunction: function test() {} 1967 | }; 1968 | var simple = function simple() {}; 1969 | var simple_foo = [1, 2, 3, 4, 5]; 1970 | 1971 | Foo.Image = function(width, height, data){ 1972 | this.width = width || 0; 1973 | this.height = height || 0; 1974 | this.data = data || []; 1975 | }; 1976 | 1977 | Bar.test = [1, 2, 3, 4]; 1978 | 1979 | class MyClass { 1980 | myFunction() { 1981 | return 12; 1982 | } 1983 | } 1984 | 1985 | const single = 'single'; 1986 | 1987 | const myVariable = new MyClass(); 1988 | 1989 | /*** EXPORTS FROM exports-loader ***/ 1990 | export default Foo; 1991 | export { 1992 | Bar 1993 | }; 1994 | " 1995 | `; 1996 | 1997 | exports[`loader should work with the "module" module format for ["default Foo","named Bar"] export list: result 1`] = ` 1998 | { 1999 | "Bar": { 2000 | "test": [ 2001 | 1, 2002 | 2, 2003 | 3, 2004 | 4, 2005 | ], 2006 | }, 2007 | "default": { 2008 | "Image": [Function], 2009 | }, 2010 | } 2011 | `; 2012 | 2013 | exports[`loader should work with the "module" module format for ["default Foo","named Bar"] export list: warnings 1`] = `[]`; 2014 | 2015 | exports[`loader should work with the "module" module format for ["named Foo Bar","named Bar"] export list: errors 1`] = ` 2016 | [ 2017 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 2018 | Error: Duplicate "Bar" (as "alias"), "Bar" (as "name") identifiers found in "", 2019 | ] 2020 | `; 2021 | 2022 | exports[`loader should work with the "module" module format for ["named Foo Bar","named Bar"] export list: warnings 1`] = `[]`; 2023 | 2024 | exports[`loader should work with the "module" module format for ["named Foo Baz","named Bar Baz"] export list: errors 1`] = ` 2025 | [ 2026 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 2027 | Error: Duplicate "Baz" (as "alias"), "Baz" (as "alias") identifiers found in "", 2028 | ] 2029 | `; 2030 | 2031 | exports[`loader should work with the "module" module format for ["named Foo Baz","named Bar Baz"] export list: warnings 1`] = `[]`; 2032 | 2033 | exports[`loader should work with the "module" module format for ["named Foo FooA","named Bar BarA"] export list: errors 1`] = `[]`; 2034 | 2035 | exports[`loader should work with the "module" module format for ["named Foo FooA","named Bar BarA"] export list: module 1`] = ` 2036 | "var Foo = Foo || {}; 2037 | var Bar = Bar || {}; 2038 | var Baz = { 2039 | nestedNumber: '12', 2040 | nestedFunction: function test() {} 2041 | }; 2042 | var simple = function simple() {}; 2043 | var simple_foo = [1, 2, 3, 4, 5]; 2044 | 2045 | Foo.Image = function(width, height, data){ 2046 | this.width = width || 0; 2047 | this.height = height || 0; 2048 | this.data = data || []; 2049 | }; 2050 | 2051 | Bar.test = [1, 2, 3, 4]; 2052 | 2053 | class MyClass { 2054 | myFunction() { 2055 | return 12; 2056 | } 2057 | } 2058 | 2059 | const single = 'single'; 2060 | 2061 | const myVariable = new MyClass(); 2062 | 2063 | /*** EXPORTS FROM exports-loader ***/ 2064 | export { 2065 | Foo as FooA, 2066 | Bar as BarA 2067 | }; 2068 | " 2069 | `; 2070 | 2071 | exports[`loader should work with the "module" module format for ["named Foo FooA","named Bar BarA"] export list: result 1`] = ` 2072 | { 2073 | "BarA": { 2074 | "test": [ 2075 | 1, 2076 | 2, 2077 | 3, 2078 | 4, 2079 | ], 2080 | }, 2081 | "FooA": { 2082 | "Image": [Function], 2083 | }, 2084 | } 2085 | `; 2086 | 2087 | exports[`loader should work with the "module" module format for ["named Foo FooA","named Bar BarA"] export list: warnings 1`] = `[]`; 2088 | 2089 | exports[`loader should work with the "module" module format for ["named Foo default","named Bar BarA"] export list: errors 1`] = `[]`; 2090 | 2091 | exports[`loader should work with the "module" module format for ["named Foo default","named Bar BarA"] export list: module 1`] = ` 2092 | "var Foo = Foo || {}; 2093 | var Bar = Bar || {}; 2094 | var Baz = { 2095 | nestedNumber: '12', 2096 | nestedFunction: function test() {} 2097 | }; 2098 | var simple = function simple() {}; 2099 | var simple_foo = [1, 2, 3, 4, 5]; 2100 | 2101 | Foo.Image = function(width, height, data){ 2102 | this.width = width || 0; 2103 | this.height = height || 0; 2104 | this.data = data || []; 2105 | }; 2106 | 2107 | Bar.test = [1, 2, 3, 4]; 2108 | 2109 | class MyClass { 2110 | myFunction() { 2111 | return 12; 2112 | } 2113 | } 2114 | 2115 | const single = 'single'; 2116 | 2117 | const myVariable = new MyClass(); 2118 | 2119 | /*** EXPORTS FROM exports-loader ***/ 2120 | export { 2121 | Foo as default, 2122 | Bar as BarA 2123 | }; 2124 | " 2125 | `; 2126 | 2127 | exports[`loader should work with the "module" module format for ["named Foo default","named Bar BarA"] export list: result 1`] = ` 2128 | { 2129 | "BarA": { 2130 | "test": [ 2131 | 1, 2132 | 2, 2133 | 3, 2134 | 4, 2135 | ], 2136 | }, 2137 | "default": { 2138 | "Image": [Function], 2139 | }, 2140 | } 2141 | `; 2142 | 2143 | exports[`loader should work with the "module" module format for ["named Foo default","named Bar BarA"] export list: warnings 1`] = `[]`; 2144 | 2145 | exports[`loader should work with the "module" module format for ["named Foo","named Bar Foo"] export list: errors 1`] = ` 2146 | [ 2147 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 2148 | Error: Duplicate "Foo" (as "name"), "Foo" (as "alias") identifiers found in "", 2149 | ] 2150 | `; 2151 | 2152 | exports[`loader should work with the "module" module format for ["named Foo","named Bar Foo"] export list: warnings 1`] = `[]`; 2153 | 2154 | exports[`loader should work with the "module" module format for ["named Foo","named Bar"] export list: errors 1`] = `[]`; 2155 | 2156 | exports[`loader should work with the "module" module format for ["named Foo","named Bar"] export list: module 1`] = ` 2157 | "var Foo = Foo || {}; 2158 | var Bar = Bar || {}; 2159 | var Baz = { 2160 | nestedNumber: '12', 2161 | nestedFunction: function test() {} 2162 | }; 2163 | var simple = function simple() {}; 2164 | var simple_foo = [1, 2, 3, 4, 5]; 2165 | 2166 | Foo.Image = function(width, height, data){ 2167 | this.width = width || 0; 2168 | this.height = height || 0; 2169 | this.data = data || []; 2170 | }; 2171 | 2172 | Bar.test = [1, 2, 3, 4]; 2173 | 2174 | class MyClass { 2175 | myFunction() { 2176 | return 12; 2177 | } 2178 | } 2179 | 2180 | const single = 'single'; 2181 | 2182 | const myVariable = new MyClass(); 2183 | 2184 | /*** EXPORTS FROM exports-loader ***/ 2185 | export { 2186 | Foo, 2187 | Bar 2188 | }; 2189 | " 2190 | `; 2191 | 2192 | exports[`loader should work with the "module" module format for ["named Foo","named Bar"] export list: result 1`] = ` 2193 | { 2194 | "Bar": { 2195 | "test": [ 2196 | 1, 2197 | 2, 2198 | 3, 2199 | 4, 2200 | ], 2201 | }, 2202 | "Foo": { 2203 | "Image": [Function], 2204 | }, 2205 | } 2206 | `; 2207 | 2208 | exports[`loader should work with the "module" module format for ["named Foo","named Bar"] export list: warnings 1`] = `[]`; 2209 | 2210 | exports[`loader should work with the "module" module format for ["named Foo","named Foo"] export list: errors 1`] = ` 2211 | [ 2212 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 2213 | Error: Duplicate "Foo" (as "name"), "Foo" (as "name") identifiers found in "", 2214 | ] 2215 | `; 2216 | 2217 | exports[`loader should work with the "module" module format for ["named Foo","named Foo"] export list: warnings 1`] = `[]`; 2218 | 2219 | exports[`loader should work with the "module" module format for {"syntax":"single","name":"Foo","alias":"FooA"} export list: errors 1`] = ` 2220 | [ 2221 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 2222 | Error: The "single" syntax can't have "FooA" alias in "", 2223 | ] 2224 | `; 2225 | 2226 | exports[`loader should work with the "module" module format for {"syntax":"single","name":"Foo","alias":"FooA"} export list: warnings 1`] = `[]`; 2227 | 2228 | exports[`loader should work with the "module" module format for {"syntax":"single","name":"Foo"} export list: errors 1`] = ` 2229 | [ 2230 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 2231 | Error: The "module" format can't be used with the "single" syntax export in "", 2232 | ] 2233 | `; 2234 | 2235 | exports[`loader should work with the "module" module format for {"syntax":"single","name":"Foo"} export list: warnings 1`] = `[]`; 2236 | 2237 | exports[`loader should work with the "module" module format for {"syntax":"unknown","name":"Foo"} export list: errors 1`] = ` 2238 | [ 2239 | "ModuleBuildError: Module build failed (from \`replaced original path\`): 2240 | ValidationError: Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema.", 2241 | ] 2242 | `; 2243 | 2244 | exports[`loader should work with the "module" module format for {"syntax":"unknown","name":"Foo"} export list: warnings 1`] = `[]`; 2245 | --------------------------------------------------------------------------------