{"id":15314015,"url":"https://github.com/vanruesc/inline-import","last_synced_at":"2025-10-08T23:32:19.602Z","repository":{"id":49034910,"uuid":"91131971","full_name":"vanruesc/inline-import","owner":"vanruesc","description":"A tool that inlines file imports.","archived":true,"fork":false,"pushed_at":"2019-04-09T18:05:14.000Z","size":115,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-13T05:36:25.415Z","etag":null,"topics":["build","compile-time","custom","embed","external","files","import","inline"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vanruesc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-12T21:46:34.000Z","updated_at":"2023-03-07T09:12:45.000Z","dependencies_parsed_at":"2022-09-08T16:41:11.315Z","dependency_job_id":null,"html_url":"https://github.com/vanruesc/inline-import","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanruesc%2Finline-import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanruesc%2Finline-import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanruesc%2Finline-import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanruesc%2Finline-import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vanruesc","download_url":"https://codeload.github.com/vanruesc/inline-import/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235374478,"owners_count":18979732,"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":["build","compile-time","custom","embed","external","files","import","inline"],"created_at":"2024-10-01T08:44:10.970Z","updated_at":"2025-10-08T23:32:14.304Z","avatar_url":"https://github.com/vanruesc.png","language":"JavaScript","readme":"# Inline Import\n\n[![Build status](https://travis-ci.org/vanruesc/inline-import.svg?branch=master)](https://travis-ci.org/vanruesc/inline-import)\n[![npm version](https://badge.fury.io/js/inline-import.svg)](https://badge.fury.io/js/inline-import)\n[![Dependencies](https://david-dm.org/vanruesc/inline-import.svg?branch=master)](https://david-dm.org/vanruesc/inline-import)\n\nA tool that inlines custom file imports.\n\n\n## Use Case\n\nInstead of loading external files at runtime, you may wish to integrate the raw file contents directly into your\nJavaScript files at build time. This tool allows you to use the native ```import``` syntax to include any data:\n\n```javascript\nimport data from \"./data.png\";\n```\n\nThe type of the imported file can be anything. You only need to specify a preferred encoding for each file type.\n\n\n## Installation\n\n```sh\nnpm install inline-import\n``` \n\n\n## Usage\n\n### Command Line Interface (CLI)\n\nThe command line tool can be invoked using the `inline-import` command. It requires a configuration in which the\nsource paths and the [options](#options) are specified. You can decide whether you want to provide the configuration\nvia `package.json` or as a standalone file. \n\nIf there is no configuration in `package.json`, the tool will look for a configuration file with the\ndefault name `.inline-import.json` in the current working directory.\n\n```sh\ninline-import -c config/inline-import.json\n```\n\nAffected files will automatically be copied into a backup directory before they are modified.\nYou can restore the original files by using the `--restore` option.\n\n| Option    | Shorthand | Description                               |\n|-----------|-----------|-------------------------------------------|\n| --config  | -c        | Specifies an alternative config path      |\n| --backup  | -b        | Only copies files into a backup directory |\n| --restore | -r        | Restores files from the backup directory  |\n\n\n### JavaScript API\n\nThe immediate inlining process is __destructive__. Affected files will be changed __permanently__.  \nTo inline your file imports, you need to specify the path to the JavaScript \nfile that should be modified. Additionally, you need to define the \n```extensions``` of the relevant import statements.\n\n#### text.txt\n\n```\nhello world\n```\n\n#### index.js\n\n```javascript\nimport component from \"module\";\nimport text from \"./text.txt\";\n```\n\n#### inline.js\n\n```javascript\nimport InlineImport from \"inline-import\";\n\nInlineImport.transform(\"index.js\", {\n\n\textensions: {\n\t\t\".txt\": \"utf8\"\n\t}\n\n}).then(modified =\u003e {\n\n\tconsole.log(modified ? \"Success!\" : \"Nothing changed\");\n\n}).catch(console.error);\n```\n\n#### index.js (inlined)\n\n```javascript\nimport component from \"module\";\nconst text = \"hello world\";\n```\n\n\n## Options\n\n- Command line exclusive:\n  - You must specify a source path or a list of paths under `src`. Glob patterns are supported.\n  - An alternative `backup` path may be specified. The default path is _.backup_.\n- You may define a specific `encoding` for the JavaScript files that will be processed. \nUse one of the possible encoding values specified in node's [Buffer](https://github.com/nodejs/node/blob/master/lib/buffer.js) class. \nThe default encoding is _utf8_.\n- Only imports with matching file `extensions` will be considered. Each extension must define its own encoding.\n- If, for some reason, you don't want to use the _const_ statement, set `useVar` to _true_.  \n\n#### .inline-import.json\n\n```javascript\n{\n\t\"src\": [\"src/**/*.js\"],\n\t\"backup\": \"path/to/backup\",\n\t\"encoding\": \"utf8\",\n\t\"useVar\": true,\n\t\"extensions\": {\n\t\t\".html\": \"utf8\",\n\t\t\".png\": \"base64\"\n\t}\n}\n```\n\n#### package.json\n\n```javascript\n{\n\t\"inlineImport\": {\n\t\t\"src\": \"src/**/*.js\",\n\t\t\"extensions\": {}\n\t}\n}\n```\n\n#### inline.js\n\n```javascript\nInlineImport.transform(filePath, {\n\tencoding: \"utf8\",\n\tuseVar: true,\n\textensions: {}\n}).catch(e =\u003e console.error(e));\n```\n\n\n## Build Tool Integration\n\n - [Inline Import Grunt plugin](https://github.com/vanruesc/grunt-inline-import)\n\n\n## Contributing\n\nMaintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvanruesc%2Finline-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvanruesc%2Finline-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvanruesc%2Finline-import/lists"}