{"id":15690214,"url":"https://github.com/marella/new-url-loader","last_synced_at":"2025-05-07T23:30:05.462Z","repository":{"id":44346279,"uuid":"377794392","full_name":"marella/new-url-loader","owner":"marella","description":"A tiny alternative to url-loader and file-loader for webpack 5.","archived":false,"fork":false,"pushed_at":"2022-03-13T16:07:29.000Z","size":44,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-02T10:11:32.119Z","etag":null,"topics":["file-loader","url-loader","webpack","webpack-loader"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marella.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-17T10:39:42.000Z","updated_at":"2024-02-14T02:06:16.000Z","dependencies_parsed_at":"2022-09-26T17:11:24.545Z","dependency_job_id":null,"html_url":"https://github.com/marella/new-url-loader","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marella%2Fnew-url-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marella%2Fnew-url-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marella%2Fnew-url-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marella%2Fnew-url-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marella","download_url":"https://codeload.github.com/marella/new-url-loader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223817760,"owners_count":17207947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file-loader","url-loader","webpack","webpack-loader"],"created_at":"2024-10-03T18:08:20.009Z","updated_at":"2024-11-09T11:03:06.307Z","avatar_url":"https://github.com/marella.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [new-url-loader](https://github.com/marella/new-url-loader) [![tests](https://github.com/marella/new-url-loader/actions/workflows/tests.yml/badge.svg)](https://github.com/marella/new-url-loader/actions/workflows/tests.yml) [![Coverage Status](https://coveralls.io/repos/github/marella/new-url-loader/badge.svg)](https://coveralls.io/github/marella/new-url-loader) [![install size](https://packagephobia.com/badge?p=new-url-loader)](https://packagephobia.com/result?p=new-url-loader)\n\nA tiny alternative to `url-loader` and `file-loader` for webpack 5.\n\nThe `url-loader` and `file-loader` are deprecated in webpack 5 and replaced by [asset modules](https://webpack.js.org/guides/asset-modules/). Loaders that are used with `url-loader` or `file-loader` (example: `@svgr/webpack` in Create React App) might still need them. `new-url-loader` provides the functionality of both `url-loader` and `file-loader` using asset modules and [URL assets](https://webpack.js.org/guides/asset-modules/#url-assets).\n\n## Installation\n\n```sh\nnpm install new-url-loader --save-dev\n```\n\n## Usage\n\nIf you are using `url-loader` or `file-loader` with another loader (example: `@svgr/webpack`), you can replace them with `new-url-loader`. The following examples show how to configure webpack to load SVGs using `@svgr/webpack`.\n\n### Replacing `url-loader`\n\n**Old**\n\n```js\n{\n  test: /\\.svg$/,\n  use: ['@svgr/webpack', 'url-loader'],\n}\n```\n\n**New**\n\n```js\n{\n  test: /\\.svg$/,\n  oneOf: [\n    {\n      dependency: { not: ['url'] }, // exclude new URL calls\n      use: ['@svgr/webpack', 'new-url-loader'],\n    },\n    {\n      type: 'asset', // export a data URI or emit a separate file\n    },\n  ],\n}\n```\n\nBy default, a file with size less than 8kb will be inlined as a data URI and emitted as a separate file otherwise. To change the file size limit, use:\n\n```js\n{\n  type: 'asset',\n  parser: {\n    dataUrlCondition: {\n      maxSize: 4 * 1024, // 4kb\n    },\n  },\n}\n```\n\nYou can also specify a function to decide whether to inline a file or not. [Learn more](https://webpack.js.org/configuration/module/#ruleparserdataurlcondition)\n\n### Replacing `file-loader`\n\n**Old**\n\n```js\n{\n  test: /\\.svg$/,\n  use: ['@svgr/webpack', 'file-loader'],\n}\n```\n\n**New**\n\n```js\n{\n  test: /\\.svg$/,\n  oneOf: [\n    {\n      dependency: { not: ['url'] }, // exclude new URL calls\n      use: ['@svgr/webpack', 'new-url-loader'],\n    },\n    {\n      type: 'asset/resource', // emit a separate file\n    },\n  ],\n}\n```\n\nBy default, files are emitted with `[hash][ext][query]` name to output directory. To customize the output filename, use:\n\n```js\n{\n  type: 'asset/resource',\n  generator: {\n    filename: 'static/media/[name].[hash][ext]',\n  },\n}\n```\n\nIt also works with `asset` module type. [Learn more](https://webpack.js.org/guides/asset-modules/#custom-output-filename)\n\n### Server Side Rendering\n\nFor Server Side Rendering (SSR) when base URL is not known by server, set [`module.parser.javascript.url`](https://webpack.js.org/configuration/module/#moduleparserjavascripturl) to `'relative'` to avoid generating URLs like `file:///path/to/project/dist/file.svg`. See #1.\n\n## Examples\n\nSee [examples](https://github.com/marella/new-url-loader/tree/main/examples/svgr).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarella%2Fnew-url-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarella%2Fnew-url-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarella%2Fnew-url-loader/lists"}