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

aurelia-extract-clean-loader

v5.0.0

Published

Remove Aurelia require tags of files that are being extracted using the Webpack's Extract Text Plugin

Downloads

40

Readme

Aurelia Extract Clean

GitHub Workflow Status (main) Coveralls github David

Remove Aurelia require tags of files that are being extracted using the Webpack's Mini CSS extract plugin.

If you are wondering why I built this, go to the Motivation section.

Usage

On the modules.rules section of your Webpack configuration, you probably already have the html-loader to handle Aurelia's views, you just need to add aurelia-extract-clean-loader before it so it will take HTML, parse it and remove the extracted requires:

...
{
  test: /\.html$/,
  use: [
    'aurelia-extract-clean-loader',
    'html-loader',
  ],
},
...

Now, it wouldn't be that cool if the loader removed ALL your requires assuming they are being extracted right? Well, for that reason is that you need to add an special attribute to the tags you want removed:

<template>
  <require from="./my-styles.scss" extract="true"></require>
  <require from="some/component"></require>
<template>

On the case of the code above, the require for my-styles will be removed and the other won't.

Options

The loader has a few options that you can modify if the default values don't suit your needs:

| Name | Type | Description | |------------------|----------|--------------------------------------------------------------------------------------------------------------| | extensions | Array | The list of extensions to validate on the require tags. Default: ['css', 'scss', 'sass', 'less']. | | attributeName | String | The name of the attribute the require needs to have in order to be removed. Default: 'extract'. | | attributeValue | String | The value of the custom attribute the require needs to have in order to be removed. Default: 'true'. |

To modify any of them, just change the syntax to an object and use the options key:

...
{
  test: /\.html$/,
  use: [
    {
      loader: 'aurelia-extract-clean-loader',
      options: {
        extensions: ['xcss'],
        attributeName: 'remove',
        attributeValue: 'yes',
      },
    },
    'html-loader',
  ],
},
...

That example would make the loader remove require tags like this one:

<template>
  <require from="some-weird-file.xcss" remove="yes"></require>
</template>

Development

NPM/Yarn Tasks

| Task | Description | |------------|-------------------------------------| | test | Run the project unit tests. | | lint | Lint the modified files. | | lint:all | Lint the entire project code. | | docs | Generate the project documentation. |

Repository hooks

I use husky to automatically install the repository hooks so...

  1. The code will be formatted and linted before any commit.
  2. The dependencies will be updated after every merge.
  3. The tests will run before pushing.

Commits convention

I use conventional commits with commitlint in order to support semantic releases. The one that sets it up is actually husky, that installs a script that runs commitlint on the git commit command.

The configuration is on the commitlint property of the package.json.

Releases

I use semantic-release and a GitHub action to automatically release on NPM everything that gets merged to main.

The configuration for semantic-release is on ./releaserc and the workflow for the release is on ./.github/workflow/release.yml.

Testing

I use Jest to test the project.

The configuration file is on ./.jestrc.js, the tests are on ./tests and the script that runs it is on ./utils/scripts/test.

Linting && Formatting

I use ESlint with my own custom configuration to validate all the JS code. The configuration file for the project code is on ./.eslintrc and the one for the tests is on ./tests/.eslintrc. There's also an ./.eslintignore to exclude some files on the process. The script that runs it is on ./utils/scripts/lint-all.

For formatting I use Prettier with my custom configuration. The configuration file for the project code is on ./.prettierrc.

Documentation

I use JSDoc to generate an HTML documentation site for the project.

The configuration file is on ./.jsdoc.js and the script that runs it is on ./utils/scripts/docs.

Motivation

I put this at the end because no one usually reads it :P.

A few weeks ago I started playing around with Aurelia and I really liked it. I think one of the best features is how it solves separation of concerns by using the require tag on the views to specify the dependencies of the UI while keeping the controller/model focused on the logic.

Now, I'm also a big fan of Webpack, so is not surprise I'm using both of them together; but here's the problem that made me write this loader:

I'm sure any Webpack user out there uses, or at least is aware of, the Mini CSS extract plugin (the updated version of the old Extract Text Plugin): A plugin that takes all the chunks of an specific type and puts them together on a single file.

Most people (like me) uses it to extract stylesheets and create a "style bundle".

The problem is that when you have a require tag for a stylesheet (or any file) that is going to be extracted by the the plugin, the contents of the file end up on your extracted bundle, but since the tag is still on the template, Aurelia will try to access it on runtime and kill your app with an error.

The way this was solved on the official Aurelia Webpack skeleton was by removing the Extract Text Plugin from the stylesheets required by views and let Aurelia inject the styles on the <head> during runtime.

I really wanted to use the plugin and put all my styles on a bundle and only inject on the <head> what I consider important, but the only workaround was to do and import/require on the model/controller file, so it wouldn't be detected by Aurelia.

Well, that's why I wrote this loader: I want to require my stylesheets on my views and I want the Mini CSS extract plugin to bundle them.