├── test ├── src │ ├── a.js │ ├── b.js │ ├── c.js │ ├── hi.jpg │ ├── fixtures │ │ ├── fileLoader.js │ │ ├── external.js │ │ └── simple.js │ ├── hi.js │ └── expected │ │ ├── simple.js.map │ │ ├── simple.js │ │ ├── external.js.map │ │ ├── fileLoader.js.map │ │ ├── fileLoader.js │ │ └── external.js └── test.js ├── .npmignore ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── package.json ├── LICENSE ├── README.md └── index.js /test/src/a.js: -------------------------------------------------------------------------------- 1 | export default 'a'; 2 | -------------------------------------------------------------------------------- /test/src/b.js: -------------------------------------------------------------------------------- 1 | export default 'b'; 2 | -------------------------------------------------------------------------------- /test/src/c.js: -------------------------------------------------------------------------------- 1 | export default 'c'; 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Everything 2 | * 3 | 4 | !index.js 5 | -------------------------------------------------------------------------------- /test/src/hi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikdesjardins/webpack-rollup-loader/HEAD/test/src/hi.jpg -------------------------------------------------------------------------------- /test/src/fixtures/fileLoader.js: -------------------------------------------------------------------------------- 1 | import { filename } from '../hi'; 2 | 3 | export const hi = filename; 4 | -------------------------------------------------------------------------------- /test/src/fixtures/external.js: -------------------------------------------------------------------------------- 1 | import a from '../a'; 2 | import b from '../b'; 3 | 4 | export default a + b; 5 | -------------------------------------------------------------------------------- /test/src/hi.js: -------------------------------------------------------------------------------- 1 | import filename from 'file-loader?name=[name].[ext]!./hi.jpg'; 2 | 3 | export { filename }; 4 | -------------------------------------------------------------------------------- /test/src/fixtures/simple.js: -------------------------------------------------------------------------------- 1 | import a from '../a'; 2 | import b from '../b'; 3 | import c from '../c'; 4 | 5 | export default a + b + c; 6 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - v*.*.* 9 | pull_request: 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v1 16 | - uses: actions/setup-node@v1 17 | with: 18 | node-version: '12.x' 19 | registry-url: 'https://registry.npmjs.org' 20 | - run: npm install 21 | - run: npm test 22 | - run: npm publish 23 | if: startsWith(github.ref, 'refs/tags/') 24 | env: 25 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | 35 | # IntelliJ 36 | *.iml 37 | .idea 38 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webpack-rollup-loader", 3 | "version": "0.8.1", 4 | "description": "Webpack loader that uses Rollup, which calls back into Webpack for module resolution.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "ava test/test.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/erikdesjardins/webpack-rollup-loader.git" 12 | }, 13 | "keywords": [ 14 | "webpack" 15 | ], 16 | "author": "Erik Desjardins", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/erikdesjardins/webpack-rollup-loader/issues" 20 | }, 21 | "homepage": "https://github.com/erikdesjardins/webpack-rollup-loader#readme", 22 | "peerDependencies": { 23 | "webpack": ">=3.3.0", 24 | "rollup": "^1.0.0 || ^2.0.0" 25 | }, 26 | "devDependencies": { 27 | "ava": "^2.4.0", 28 | "file-loader": "^6.2.0", 29 | "memory-fs": "^0.5.0", 30 | "rollup": "^2.57.0", 31 | "rollup-plugin-commonjs": "^10.1.0", 32 | "webpack": "^5.53.0" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Erik Desjardins 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # webpack-rollup-loader 2 | 3 | Webpack loader that uses Rollup, which calls back into Webpack for module resolution. 4 | 5 | Inspired by [egoist/rollup-loader](https://github.com/egoist/rollup-loader). 6 | 7 | ## Installation 8 | 9 | `npm install --save-dev webpack-rollup-loader` 10 | 11 | Rollup is a peer dependency, and must also be installed: 12 | 13 | `npm install --save-dev rollup` 14 | 15 | ## Usage 16 | 17 | **Note:** This loader must only be applied once to the entry module. Using it to load all `.js` files (or just recursively) _will_ produce incorrect code. 18 | 19 | If you use Babel, make sure that it isn't [converting ES6 imports to CommonJS](https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs). 20 | 21 | **webpack.config.js:** 22 | 23 | ```js 24 | module.exports = { 25 | entry: 'entry.js', 26 | module: { 27 | rules: [ 28 | { 29 | test: /entry\.js$/, 30 | use: [{ 31 | loader: 'webpack-rollup-loader', 32 | options: { 33 | // OPTIONAL: any rollup options (except `entry`) 34 | // e.g. 35 | external: [/* modules that shouldn't be rollup'd */] 36 | }, 37 | }] 38 | }, 39 | 40 | // ...other rules as usual 41 | { 42 | test: /\.js$/, 43 | use: ['babel-loader'] // can be applied to .js files as usual 44 | } 45 | ] 46 | } 47 | }; 48 | ``` 49 | -------------------------------------------------------------------------------- /test/src/expected/simple.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"bundle.js","mappings":";;UAAA;UACA;;;;;WCDA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;ACNA;;ACAA;;ACAA;;ACIA,aAAe,CAAC,GAAG,CAAC,GAAG,CAAC","sources":["webpack://webpack-rollup-loader/webpack/bootstrap","webpack://webpack-rollup-loader/webpack/runtime/define property getters","webpack://webpack-rollup-loader/webpack/runtime/hasOwnProperty shorthand","webpack://webpack-rollup-loader/webpack/runtime/make namespace object","webpack://webpack-rollup-loader/test/src/webpack:/test/src/a.js","webpack://webpack-rollup-loader/test/src/webpack:/test/src/b.js","webpack://webpack-rollup-loader/test/src/webpack:/test/src/c.js","webpack://webpack-rollup-loader/test/src/fixtures/simple.js"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export default 'a';\n","export default 'b';\n","export default 'c';\n","import a from '../a';\nimport b from '../b';\nimport c from '../c';\n\nexport default a + b + c;\n"],"names":[],"sourceRoot":""} -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import test from 'ava'; 4 | import webpack from 'webpack'; 5 | import MemoryFS from 'memory-fs'; 6 | import commonjs from 'rollup-plugin-commonjs'; 7 | 8 | function normalize(string) { 9 | return string 10 | .replace(/(\r\n|\r|\n)/g, '\n') 11 | .trim(); 12 | } 13 | 14 | async function fixture(t, entry, options) { 15 | const entryPath = path.join(__dirname, 'src', 'fixtures', entry); 16 | const compiler = webpack({ 17 | entry: entryPath, 18 | bail: true, 19 | output: { 20 | path: '/', 21 | filename: 'bundle.js' 22 | }, 23 | mode: 'development', 24 | devtool: 'source-map', 25 | module: { 26 | rules: [{ 27 | test: entryPath, 28 | use: [{ 29 | loader: path.join(__dirname, '../index.js'), 30 | options, 31 | }] 32 | }], 33 | }, 34 | }); 35 | 36 | const mockFs = new MemoryFS(); 37 | 38 | compiler.outputFileSystem = mockFs; 39 | 40 | await new Promise((resolve, reject) => { 41 | compiler.run((err, stats) => { 42 | stats.hasErrors() ? reject(stats.toString()) : resolve(stats); 43 | }); 44 | }); 45 | 46 | /* 47 | const bundle = mockFs.readFileSync('/bundle.js', 'utf8'); 48 | fs.writeFileSync(path.join(__dirname, 'src', 'expected', entry), bundle.replace(/\r/g, '')); 49 | const sourcemap = mockFs.readFileSync('/bundle.js.map', 'utf8'); 50 | fs.writeFileSync(path.join(__dirname, 'src', 'expected', `${entry}.map`), sourcemap.replace(/\\r/g, '')); 51 | */ 52 | 53 | t.is( 54 | normalize(mockFs.readFileSync('/bundle.js', 'utf8')), 55 | normalize(fs.readFileSync(path.join(__dirname, 'src', 'expected', entry), 'utf8')), 56 | ); 57 | 58 | t.is( 59 | normalize(mockFs.readFileSync('/bundle.js.map', 'utf8')), 60 | normalize(fs.readFileSync(path.join(__dirname, 'src', 'expected', `${entry}.map`), 'utf8')), 61 | ); 62 | } 63 | 64 | test('simple', fixture, 'simple.js'); 65 | 66 | test('plugins option', fixture, 'fileLoader.js', { plugins: [commonjs({ extensions: ['.js', '.jpg'] })] }); 67 | 68 | test('external option', fixture, 'external.js', { external: [path.join(__dirname, 'src', 'b.js')] }); 69 | -------------------------------------------------------------------------------- /test/src/expected/simple.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ // The require scope 4 | /******/ var __webpack_require__ = {}; 5 | /******/ 6 | /************************************************************************/ 7 | /******/ /* webpack/runtime/define property getters */ 8 | /******/ (() => { 9 | /******/ // define getter functions for harmony exports 10 | /******/ __webpack_require__.d = (exports, definition) => { 11 | /******/ for(var key in definition) { 12 | /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 13 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 14 | /******/ } 15 | /******/ } 16 | /******/ }; 17 | /******/ })(); 18 | /******/ 19 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 20 | /******/ (() => { 21 | /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 22 | /******/ })(); 23 | /******/ 24 | /******/ /* webpack/runtime/make namespace object */ 25 | /******/ (() => { 26 | /******/ // define __esModule on exports 27 | /******/ __webpack_require__.r = (exports) => { 28 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 29 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 30 | /******/ } 31 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 32 | /******/ }; 33 | /******/ })(); 34 | /******/ 35 | /************************************************************************/ 36 | var __webpack_exports__ = {}; 37 | /*!*************************************!*\ 38 | !*** ./test/src/fixtures/simple.js ***! 39 | \*************************************/ 40 | __webpack_require__.r(__webpack_exports__); 41 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { 42 | /* harmony export */ "default": () => (/* binding */ simple) 43 | /* harmony export */ }); 44 | var a = 'a'; 45 | 46 | var b = 'b'; 47 | 48 | var c = 'c'; 49 | 50 | var simple = a + b + c; 51 | 52 | 53 | 54 | /******/ })() 55 | ; 56 | //# sourceMappingURL=bundle.js.map -------------------------------------------------------------------------------- /test/src/expected/external.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"bundle.js","mappings":";;;;;;;;;;;;;;AAAA,iEAAe,GAAG,EAAC;;;;;;;UCAnB;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;;;ACNA;;ACGA,eAAe,CAAC,GAAG,6CAAC","sources":["webpack://webpack-rollup-loader/./test/src/b.js","webpack://webpack-rollup-loader/webpack/bootstrap","webpack://webpack-rollup-loader/webpack/runtime/define property getters","webpack://webpack-rollup-loader/webpack/runtime/hasOwnProperty shorthand","webpack://webpack-rollup-loader/webpack/runtime/make namespace object","webpack://webpack-rollup-loader/test/src/webpack:/test/src/a.js","webpack://webpack-rollup-loader/test/src/fixtures/external.js"],"sourcesContent":["export default 'b';\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export default 'a';\n","import a from '../a';\nimport b from '../b';\n\nexport default a + b;\n"],"names":[],"sourceRoot":""} -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Erik Desjardins 3 | * See LICENSE file in root directory for full license. 4 | */ 5 | 6 | 'use strict'; 7 | 8 | var path = require('path'); 9 | var rollup = require('rollup').rollup; 10 | 11 | function splitRequest(request) { 12 | var inx = request.lastIndexOf('!'); 13 | if (inx === -1) { 14 | return { 15 | loaders: '', 16 | resource: request 17 | }; 18 | } else { 19 | return { 20 | loaders: request.slice(0, inx + 1), 21 | resource: request.slice(inx + 1) 22 | }; 23 | } 24 | } 25 | 26 | module.exports = function(source, sourceMap) { 27 | var callback = this.async(); 28 | 29 | var options = this.query || {}; 30 | 31 | var entryId = this.resourcePath; 32 | 33 | rollup(Object.assign({}, options, { 34 | input: entryId, 35 | plugins: (options.plugins || []).concat({ 36 | resolveId: function(id, importerId) { 37 | if (id === entryId) { 38 | return entryId; 39 | } else { 40 | return new Promise(function(resolve, reject) { 41 | // split apart resource paths because Webpack's this.resolve() can't handle `loader!` prefixes 42 | var parts = splitRequest(id); 43 | var importerParts = splitRequest(importerId); 44 | 45 | // resolve the full path of the imported file with Webpack's module loader 46 | // this will figure out node_modules imports, Webpack aliases, etc. 47 | this.resolve(path.dirname(importerParts.resource), parts.resource, function(err, fullPath) { 48 | if (err) { 49 | reject(err); 50 | } else { 51 | resolve(parts.loaders + fullPath); 52 | } 53 | }); 54 | }.bind(this)); 55 | } 56 | }.bind(this), 57 | load: function(id) { 58 | if (id === entryId) { 59 | return { code: source, map: sourceMap }; 60 | } 61 | return new Promise(function(resolve, reject) { 62 | // load the module with Webpack 63 | // this will apply all relevant loaders, etc. 64 | this.loadModule(id, function(err, source, map, module) { 65 | if (err) { 66 | reject(err); 67 | return; 68 | } 69 | resolve({ code: source, map: map }); 70 | }); 71 | }.bind(this)); 72 | }.bind(this), 73 | }) 74 | })) 75 | .then(function(bundle) { 76 | return bundle.generate({ format: 'es', sourcemap: this.sourceMap }); 77 | }.bind(this)) 78 | .then(function(result) { 79 | var mainChunk = result.output[0]; 80 | callback(null, mainChunk.code, mainChunk.map); 81 | }, function(err) { 82 | callback(err); 83 | }); 84 | }; 85 | -------------------------------------------------------------------------------- /test/src/expected/fileLoader.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"bundle.js","mappings":";;UAAA;UACA;;;;;WCDA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,GAAG;WACH;WACA;WACA,CAAC;;;;;WCPD;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;WCNA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;WACA;;;;;;;;;;;;ACfA;;ACEY,MAAC,EAAE,GAAG","sources":["webpack://webpack-rollup-loader/webpack/bootstrap","webpack://webpack-rollup-loader/webpack/runtime/define property getters","webpack://webpack-rollup-loader/webpack/runtime/global","webpack://webpack-rollup-loader/webpack/runtime/hasOwnProperty shorthand","webpack://webpack-rollup-loader/webpack/runtime/make namespace object","webpack://webpack-rollup-loader/webpack/runtime/publicPath","webpack://webpack-rollup-loader/./test/src/hi.jpg","webpack://webpack-rollup-loader/test/src/fixtures/fileLoader.js"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.g = (function() {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","var scriptUrl;\nif (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + \"\";\nvar document = __webpack_require__.g.document;\nif (!scriptUrl && document) {\n\tif (document.currentScript)\n\t\tscriptUrl = document.currentScript.src\n\tif (!scriptUrl) {\n\t\tvar scripts = document.getElementsByTagName(\"script\");\n\t\tif(scripts.length) scriptUrl = scripts[scripts.length - 1].src\n\t}\n}\n// When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration\n// or pass an empty string (\"\") and set the __webpack_public_path__ variable from your code to use your own logic.\nif (!scriptUrl) throw new Error(\"Automatic publicPath is not supported in this browser\");\nscriptUrl = scriptUrl.replace(/#.*$/, \"\").replace(/\\?.*$/, \"\").replace(/\\/[^\\/]+$/, \"/\");\n__webpack_require__.p = scriptUrl;","export default __webpack_public_path__ + \"hi.jpg\";","import { filename } from '../hi';\n\nexport const hi = filename;\n"],"names":[],"sourceRoot":""} -------------------------------------------------------------------------------- /test/src/expected/fileLoader.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ // The require scope 4 | /******/ var __webpack_require__ = {}; 5 | /******/ 6 | /************************************************************************/ 7 | /******/ /* webpack/runtime/define property getters */ 8 | /******/ (() => { 9 | /******/ // define getter functions for harmony exports 10 | /******/ __webpack_require__.d = (exports, definition) => { 11 | /******/ for(var key in definition) { 12 | /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 13 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 14 | /******/ } 15 | /******/ } 16 | /******/ }; 17 | /******/ })(); 18 | /******/ 19 | /******/ /* webpack/runtime/global */ 20 | /******/ (() => { 21 | /******/ __webpack_require__.g = (function() { 22 | /******/ if (typeof globalThis === 'object') return globalThis; 23 | /******/ try { 24 | /******/ return this || new Function('return this')(); 25 | /******/ } catch (e) { 26 | /******/ if (typeof window === 'object') return window; 27 | /******/ } 28 | /******/ })(); 29 | /******/ })(); 30 | /******/ 31 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 32 | /******/ (() => { 33 | /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 34 | /******/ })(); 35 | /******/ 36 | /******/ /* webpack/runtime/make namespace object */ 37 | /******/ (() => { 38 | /******/ // define __esModule on exports 39 | /******/ __webpack_require__.r = (exports) => { 40 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 41 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 42 | /******/ } 43 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 44 | /******/ }; 45 | /******/ })(); 46 | /******/ 47 | /******/ /* webpack/runtime/publicPath */ 48 | /******/ (() => { 49 | /******/ var scriptUrl; 50 | /******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + ""; 51 | /******/ var document = __webpack_require__.g.document; 52 | /******/ if (!scriptUrl && document) { 53 | /******/ if (document.currentScript) 54 | /******/ scriptUrl = document.currentScript.src 55 | /******/ if (!scriptUrl) { 56 | /******/ var scripts = document.getElementsByTagName("script"); 57 | /******/ if(scripts.length) scriptUrl = scripts[scripts.length - 1].src 58 | /******/ } 59 | /******/ } 60 | /******/ // When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration 61 | /******/ // or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic. 62 | /******/ if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser"); 63 | /******/ scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/"); 64 | /******/ __webpack_require__.p = scriptUrl; 65 | /******/ })(); 66 | /******/ 67 | /************************************************************************/ 68 | var __webpack_exports__ = {}; 69 | /*!*****************************************!*\ 70 | !*** ./test/src/fixtures/fileLoader.js ***! 71 | \*****************************************/ 72 | __webpack_require__.r(__webpack_exports__); 73 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { 74 | /* harmony export */ "hi": () => (/* binding */ hi) 75 | /* harmony export */ }); 76 | var filename = __webpack_require__.p + "hi.jpg"; 77 | 78 | const hi = filename; 79 | 80 | 81 | 82 | /******/ })() 83 | ; 84 | //# sourceMappingURL=bundle.js.map -------------------------------------------------------------------------------- /test/src/expected/external.js: -------------------------------------------------------------------------------- 1 | /******/ (() => { // webpackBootstrap 2 | /******/ "use strict"; 3 | /******/ var __webpack_modules__ = ({ 4 | 5 | /***/ "./test/src/b.js": 6 | /*!***********************!*\ 7 | !*** ./test/src/b.js ***! 8 | \***********************/ 9 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 10 | 11 | __webpack_require__.r(__webpack_exports__); 12 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { 13 | /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) 14 | /* harmony export */ }); 15 | /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ('b'); 16 | 17 | 18 | /***/ }) 19 | 20 | /******/ }); 21 | /************************************************************************/ 22 | /******/ // The module cache 23 | /******/ var __webpack_module_cache__ = {}; 24 | /******/ 25 | /******/ // The require function 26 | /******/ function __webpack_require__(moduleId) { 27 | /******/ // Check if module is in cache 28 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 29 | /******/ if (cachedModule !== undefined) { 30 | /******/ return cachedModule.exports; 31 | /******/ } 32 | /******/ // Create a new module (and put it into the cache) 33 | /******/ var module = __webpack_module_cache__[moduleId] = { 34 | /******/ // no module.id needed 35 | /******/ // no module.loaded needed 36 | /******/ exports: {} 37 | /******/ }; 38 | /******/ 39 | /******/ // Execute the module function 40 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 41 | /******/ 42 | /******/ // Return the exports of the module 43 | /******/ return module.exports; 44 | /******/ } 45 | /******/ 46 | /************************************************************************/ 47 | /******/ /* webpack/runtime/define property getters */ 48 | /******/ (() => { 49 | /******/ // define getter functions for harmony exports 50 | /******/ __webpack_require__.d = (exports, definition) => { 51 | /******/ for(var key in definition) { 52 | /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 53 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 54 | /******/ } 55 | /******/ } 56 | /******/ }; 57 | /******/ })(); 58 | /******/ 59 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 60 | /******/ (() => { 61 | /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 62 | /******/ })(); 63 | /******/ 64 | /******/ /* webpack/runtime/make namespace object */ 65 | /******/ (() => { 66 | /******/ // define __esModule on exports 67 | /******/ __webpack_require__.r = (exports) => { 68 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 69 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 70 | /******/ } 71 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 72 | /******/ }; 73 | /******/ })(); 74 | /******/ 75 | /************************************************************************/ 76 | var __webpack_exports__ = {}; 77 | // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. 78 | (() => { 79 | /*!***************************************!*\ 80 | !*** ./test/src/fixtures/external.js ***! 81 | \***************************************/ 82 | __webpack_require__.r(__webpack_exports__); 83 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { 84 | /* harmony export */ "default": () => (/* binding */ external) 85 | /* harmony export */ }); 86 | /* harmony import */ var _b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../b.js */ "./test/src/b.js"); 87 | 88 | 89 | var a = 'a'; 90 | 91 | var external = a + _b_js__WEBPACK_IMPORTED_MODULE_0__["default"]; 92 | 93 | 94 | 95 | })(); 96 | 97 | /******/ })() 98 | ; 99 | //# sourceMappingURL=bundle.js.map --------------------------------------------------------------------------------