Socket
Socket
Sign inDemoInstall

@ayang4114/load_assets

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ayang4114/load_assets

Generates a JavaScript file that loads all files via 'require' in a given directory. This is stored as an exported object.


Version published
Weekly downloads
5
increased by150%
Maintainers
1
Install size
29.1 kB
Created
Weekly downloads
 

Readme

Source

load_assets

A command that generates a JavaScript file which contains an object that maps to loaded assets from a directory, including static images files, using require(...). This was built to support writing many imports/require statements for bundlers that load static assets/resources like webpack.

Install

npm install -g @ayang4114/load_assets

Usage

On the command line, execute the following command

load_assets <directory_of_assets>

Flags

Any arguments passed without a flag is treated as an argument for the --input flag, i.e. it treated as the input directory.

FlagDescriptionDefault
--inputThe path to the directory to be converted into an asset file.None
--outputThe output path name of the converted asset fileassets.js or assets.ts
--targetLangThe target language of the output asset file: either 'ts' or 'js''js'
--indentsThe number of indents in output file.2
--excludeExtA space-separated sequence of all filetype extensions to ignore.None
--includeExtA space-separated sequence of all filetype extensions to include.None

Supported Type Extensions

By default, all files with the extensions jpg, jpeg, png, and gif are included when traversing through the assets directory. These files can be ignored by adding the unwanted extensions as arguments in --excludeExt.

Example

Consider the following tree:

assets
├── moon.png
├── sun.png
├── nested_assets_1
│   ├── moon.jpg
│   └── sun.jpg
└── nested_assets_2
    ├── moon.jpg
    ├── nested_assets
    │   ├── moon.jpg
    │   └── sun.jpg
    └── sun.jpg

Then, load_assets assets will produce the following output in assets.js:

module.asset = {
  jpg: {
    "nested_assets_1": {
      "moon": require("./assets/nested_assets_1/moon.jpg"),
      "sun": require("./assets/nested_assets_1/sun.jpg"),
    },
    "nested_assets_2": {
      "moon": require("./assets/nested_assets_2/moon.jpg"),
      "nested_assets": {
        "moon": require("./assets/nested_assets_2/nested_assets/moon.jpg"),
        "sun": require("./assets/nested_assets_2/nested_assets/sun.jpg"),
      },
      "sun": require("./assets/nested_assets_2/sun.jpg"),
    },
  },
  png: {
    "moon": require("./assets/moon.png"),
    "sun": require("./assets/sun.png"),
  }
};

Contributing

Feel free to add issues or suggestions in the repository.

You can also make PRs:

  1. Fork the repository.
  2. Create a feature branch in the forked repository.
  3. Push changes to the feature branch.
  4. Submit a PR request.

License

ISC License

Keywords

FAQs

Last updated on 29 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc