├── .editorconfig ├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── .npmrc ├── fixture.js ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 16 14 | - 14 15 | - 12 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: actions/setup-node@v4 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | - run: npm install 22 | - run: npm test 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /fixture.js: -------------------------------------------------------------------------------- 1 | module.exports = '🦄'; 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = typeof __webpack_require__ !== 'undefined' ? __webpack_require__ : eval('require'); 3 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "require-fool-webpack", 3 | "version": "2.0.0", 4 | "description": "Use dynamic `require()` without webpack finding out", 5 | "license": "MIT", 6 | "repository": "sindresorhus/require-fool-webpack", 7 | "funding": "https://github.com/sponsors/sindresorhus", 8 | "author": { 9 | "name": "Sindre Sorhus", 10 | "email": "sindresorhus@gmail.com", 11 | "url": "https://sindresorhus.com" 12 | }, 13 | "sideEffects": false, 14 | "engines": { 15 | "node": ">=4" 16 | }, 17 | "scripts": { 18 | "test": "xo && ava" 19 | }, 20 | "files": [ 21 | "index.js" 22 | ], 23 | "keywords": [ 24 | "require", 25 | "import", 26 | "webpack", 27 | "lol" 28 | ], 29 | "devDependencies": { 30 | "ava": "*", 31 | "xo": "*" 32 | }, 33 | "xo": { 34 | "ignores": [ 35 | "index.js" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # require-fool-webpack 2 | 3 | > Use dynamic `require()` without webpack finding out 4 | 5 | Because [webpack is super annoying](https://github.com/webpack/webpack/issues/196). 💩 6 | 7 | You need to supply it an absolute path. 8 | 9 | 10 | ## Install 11 | 12 | ```sh 13 | npm install require-fool-webpack 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ### Before 20 | 21 | ```js 22 | const foo = require(getPath()); 23 | ``` 24 | 25 | Warning from webpack: 26 | 27 | ``` 28 | WARNING in ./app/node_modules/conf/index.js 29 | 1:33-43 Critical dependency: the request of a dependency is an expression 30 | @ ./app/node_modules/conf/index.js 31 | @ ./app/node_modules/electron-store/index.js 32 | @ ./app/config.js 33 | @ ./app/renderer/index.js 34 | ``` 35 | 36 | ### After 37 | 38 | ```js 39 | const requireFoolWebpack = require('require-fool-webpack'); 40 | const foo = requireFoolWebpack(getPath()); 41 | ``` 42 | 43 | No warning! \o/ 44 | 45 | 46 | ## License 47 | 48 | MIT © [Sindre Sorhus](https://sindresorhus.com) 49 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import requireFoolWebpack from './index.js'; 3 | 4 | test(t => { 5 | t.is(require('./fixture'), '🦄'); 6 | }); 7 | --------------------------------------------------------------------------------