# cubx-resource-resolver

> Purpose to optimize the loading of Cubbles resources in the browser. - Download and merge to a single file all direct referenced javascript resources - Download and merge to a singe file the html import files and include the merged javascript file - Dow

Latest version **1.1.2** (published 2021-01-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install cubx-resource-resolver
pnpm add cubx-resource-resolver
yarn add cubx-resource-resolver
bun add cubx-resource-resolver
```

Provides the command `cubx-resource-resolver`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2021-01-27 |
| First published | 2018-11-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 5 |
| Unpacked size | 1.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Judit Ross |
| Maintainers | jtrs |

## Links

- npm: https://www.npmjs.com/package/cubx-resource-resolver
- Repository: https://github.com/cubbles/cubx-resource-resolver
- Homepage: https://github.com/cubbles/cubx-resource-resolver#readme
- Issues: https://github.com/cubbles/cubx-resource-resolver/issues
- npm.io page: https://npm.io/package/cubx-resource-resolver

## Dependencies (5)

- [fs-extra](https://npm.io/package/fs-extra.md) ^8.0.0
- [chai-things](https://npm.io/package/chai-things.md) ^0.2.0
- [command-line-args](https://npm.io/package/command-line-args.md) ^5.0.2
- [command-line-usage](https://npm.io/package/command-line-usage.md) ^5.0.5
- [cubx-dependency-resolver](https://npm.io/package/cubx-dependency-resolver.md) ^1.3.1

## Recent versions

- 1.1.2 (latest) — 2021-01-27
- 1.1.1 — 2021-01-11
- 1.1.0 — 2021-01-08
- 1.0.5 — 2019-01-10
- 1.0.4 — 2018-11-29
- 1.0.3 — 2018-11-27
- 1.0.2 — 2018-11-26
- 1.0.1 — 2018-11-26
- 1.0.0 — 2018-11-23

## README

# cubx-resource-resolver
# Features

Purpose to optimize the loading of Cubbles resources in the browser.
- Download and merge to a single file all direct referenced javascript resources  
- Download and merge to a singe file the html import files and include the merged javascript file
- Download and merge to a single file in the the html import referenced javascript files
- Download and merge to a single file all css resource. (Direct referenced css as well as in the html import file referenced resources )  
 


# Installing

Using npm:

```bash
$ npm install cubx-resource-resolver
```
# Usage

1. Configure CRC: disable resource 
```bash
window.cubx.CRCInit.disableResourceInjection = true;
```

2\. Download and Merge all resources 

* with cli: 
```bash
cubx-resource-resolver -i test\input\artifactList.json -o test\output\ -b https://cubbles.world/pcp-sandbox/ -m dev
``` 
* in jnodejs code

```javascript
async function resolve() {
  let baseUrl = 'https://cubbles.world/sandbox/'
  let resourceList = [
    {
      path: baseUrl + 'example@1.0.0/example-artifact-1/example-artifact-1.html',
      type: 'htmlImport'
    },
    {
      path: baseUrl + 'example@1.0.0/example-artifact-1/styles/example.css',
      type: 'stylesheet'
    },
    {
      path: baseUrl + 'example@1.0.0/example-artifact-2/example-artifact-2.html',
      type: 'htmlImport'
    },
    {
      path: baseUrl + 'example@1.0.0/util1/js/util.js',
      type: 'javascript'
    }
  ];
  
  await resourceResolver.resolve(resourceList, 'output', baseUrl);
}
```
3\. Load resources after CRC resolved dependencies and fire 'depMgrReady' event manually.   
```html
<script>
  document.addEventListener('crcBeforeResourceInjection', function (evt) {
    // add scripts
    var element = document.createElement('script');
    element.setAttribute('src', '/output/scripts.js'?>');
    element.async = false;
    document.head.appendChild(element);
    // add styles
    element = document.createElement('link');
    element.setAttribute('rel', 'stylesheet');
    element.setAttribute('href', '/output/styles.css'?>');
    document.head.appendChild(element);
  
    // add templates
    element = document.createElement('link');
    element.setAttribute('rel', 'import');
    element.setAttribute('href', '/output/html-imports.html'?>');
    document.head.appendChild(element);
    // fire event for CRC, that this can continue work and not longer waiting
    window.cubx.CRC.fireDepMgrReadyEvent();
  });
</script>
```

___Hint:__ The resource list can generated with the npm modul `cubx-dependency-resolver`. Use the #resolveResourcesList Method._

__Attention:__ Exclude Polymer resources, and add separatly after the reference of webcomponent script and cubx.core.rte@2.6.0/crcLoader/main.js reference, but before other cubbles references. This will be work by minimum rte version 2.6.0.

---
_Source: https://npm.io/package/cubx-resource-resolver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
