npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-asset-inline-fixed

v1.1.8

Published

Used for Angular libraries to inline 'templateUrl' and 'styleUrls' to 'template' and 'styles'. Can be used from Node and as a CLI tool.

Downloads

3

Readme

build status

Important

This is slightly modifyed version of ng-asset-inline pakage

There is no repo for original package, so no fork no MR, just new repo.

ng-asset-inline

Helpful CLI tool for inlining Angular component templateUrl and styleUrls when bundling library code.

Highlights

  • Supports includeStylePaths (mirrors Angular CLI functionality)
  • No need to copy .js/.html/.css files over build folder
  • Inlines URLS for both .js and .metadata.json files, supporting both AOT and JIT modes for Angular
  • Written with Typescript and Rxjs

Example

ng-asset-inline build src/lib --styles 'src/styles,src/mixins'
import { ngAssetInline } from 'ng-asset-inline';
// or standard Node require:
// const { ngAssetInline } = require('ng-asset-inline');

ngAssetInline({
  build: 'build',
  source: 'src/lib',
  includeStylePaths: ['src/styles', 'src/mixins']
})
  .subscribe({
    error: err => console.log(err),
    complete: () => console.log('Angular assets inlined!');
  });

Usage

npm i -D ng-asset-inline
# equivalent to:
npm install --save-dev ng-asset-inline

All paths are relative to the console working directory that ng-asset-inline is run from.

ng-asset-inline build src/lib
ng-asset-inline <build-folder> <source-folder>

This will inline templates/styles for all .js and .metadata.json files in the build folder, using the .html/.css/.scss files from src/lib. E.g. for the component in build/datepicker/datepicker.component.js, asset paths will be resolved relative to folder src/lib/datepicker.

IncludeStyles option

ng-asset-inline --styles '<comma-separated-paths>'

Angular CLI has an option named stylePreprocessorOptions.includePaths, which is an array of folders where style pre-processors should also look for files. This CLI option mirrors that functionality.

Angular library guide

This guide will be a pretty high level step-by-step guide, but check out this video from ng-conf for more insight into the how's and why's.

1. Compile Typescript files

Before using ng-asset-inline, use the Angular compiler to generate .js, .d.ts and .metadata.json files from your .ts files. This can be done like below:

ngc -p src/lib/tsconfig.build.json
// tsconfig.build.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "rootDir": ".",
    "outDir": "./build",
    "target": "es2015",
    "module": "es2015",
    "moduleResolution": "node",
    "strict": true,
    "declaration": true,
    "experimentalDecorators": true
  },
  "files": [
    "my-lib.ts"
  ],
  "angularCompilerOptions": {
    "strictMetadataEmit": true,
    "skipTemplateCodegen": true,
    "flatModuleOutFile": "my-lib.js",
    "flatModuleId": "my-lib"
  }
}

This will generate a bunch of files in the build folder. For this example, the folder structure will look something like this:

my-lib
\___ build
 |  \____ my-lib.d.ts
 |   |___ my-lib.js
 |   |___ my-lib.metadata.json
 |   |___ awesome.component.d.ts
 |   |___ awesome.component.js
 |    \__ ...
  \_ src
      \___ lib
       |  \____ my-lib.ts
       |   |___ awesome.component.html
       |   |___ awesome.component.scss
       |   |___ awesome.component.ts
       |    \__ ...
        \_ styles

If we would look at awesome.component.js and my-lib.metadata.json we would be able to see that the component metadata are still in the URL format (the .js file shown below):

AwesomeComponent.decorators = [
    { type: Component, args: [{
                selector: 'mylib-awesome',
                templateUrl: './awesome.component.html',
                styleUrls: ['./awesome.component.scss']
            },] },
];

And that is what this library will solve! It replaces templateUrl and styleUrls with template and stylesrespectively.

AwesomeComponent.decorators = [
    { type: Component, args: [{
                selector: 'mylib-awesome',
                template: '<h1>This component is awesome!</h1>\n',
                styles: ['h1 { color: goldenrod; }\n']
            },] },
];

2. Inline templates

ng-asset-inline should make this step easy! For the above example, we only need to run the following command:

ng-asset-inline build src/lib --styles src/styles

If there are any .scss files with e.g. @import 'mixins';, they will also be looked for in the src/styles folder.

3. Rollup into FESM

Next up, is to roll all .js files up into one by using Rollup.

-- TODO --

License

MIT