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

glimmer-compiler-webpack-plugin

v0.6.1

Published

webpack plugin for compiling Glimmer components

Downloads

29

Readme

Glimmer Compiler for Webpack

This webpack plugin allows you to compile Glimmer.js components into binary bytecode.

Note: Please don't use this plugin yet. It isn't quite ready and will just frustrate you if you try to use it now. Soon! 🤗

Usage

  1. Configure the template and data table loaders.
  2. Register the GlimmerCompiler plugin with appropriate configuration options.
  3. In your entry file, load the template bytecode and data table and initialize a new Glimmer.js application.

In webpack.config.js:

const GlimmerCompiler = require('glimmer-compiler-webpack-plugin');

module.exports = {
  module: {
    rules: [
      // Tell webpack how to find component templates
      {
        test: /\.hbs$/,
        use: GlimmerCompiler.template()
      },
      // Tell webpack where to put compilation metadata
      {
        test: /data\.js$/,
        use: GlimmerCompiler.data()
      }
    ]
  },
  plugins: [
    // Register the compiler plugin and configure where to
    // put the binary bytecode (.gbx file).
    new GlimmerCompiler({
      output: 'templates.gbx',
      mode: 'module-unification'
    }),
  ]
}

In your app's entry point file:

import Application, { DOMBuilder, AsyncRenderer, BytecodeLoader } from '@glimmer/application';

import data from './data';

let bytecode = fetch('templates.gbx')
  .then(req => req.arrayBuffer());

let element = document.getElementById('app');

let app = new Application({
  builder: new DOMBuilder({ element }),
  renderer: new AsyncRenderer(),
  loader: new BytecodeLoader({ data, bytecode })
});

app.boot();

About This Plugin

Glimmer.js is a library for authoring UI components for the web. To make those components lightning fast, Glimmer compiles component templates into a binary bytecode. This plugin adds support for running the compilation process with webpack.

Component Discovery

In order to discover which components are used in a particular compilation, you must use the provided GlimmerCompiler.template() loader to load .hbs files.

module.exports = {
  module: {
    rules: [
      {
        test: /\.hbs$/,
        use: GlimmerCompiler.template()
      },
      /* ... */
    ]
  },
  /* ... */
}

Template files must be imported from the entry file or another JavaScript file in order to be included in the bundle:

import 'src/ui/components/UserProfile/template.hbs';
import 'src/ui/components/Avatar/template.hbs';
// ...

The files themselves will be removed from the JavaScript bundle and instead placed in the compiled bytecode (.gbx file).

Build Artifacts

In order to run your app in the browser, Glimmer needs two artifacts from the compilation process:

  1. A "data table" that links the Glimmer bytecode to JavaScript objects.
  2. The bytecode itself.

Data Table

The plugin will generate the data table as a module that can be imported like any other JavaScript module. You tell the compiler which module to populate with the data table using a loader.

In your webpack.config.js:

module.exports = {
  module: {
    rules: [
      {
        test: /data\.js$/,
        use: GlimmerCompiler.data()
      },
      /* ... */
    ]
  },
  /* ... */
}

Then create an empty file that matches the loader rule, like data.js.

From your entry point file, you can import the data like a normal module:

import data from './data';

Binary Bytecode

Glimmer compiles your application's templates into binary bytecode that is saved in a .gbx file. To tell where this binary should be placed in the output, pass the output configuration to the plugin constructor:

module.exports = {
  /* ... */
  plugins: [
    // Register the compiler plugin and configure where to
    // put the binary bytecode (.gbx file).
    new GlimmerCompiler({
      output: 'templates.gbx',
      mode: 'module-unification'
    }),
  ]
}

You can fetch the bytecode file at runtime in your app by using fetch() and retrieving the data as an ArrayBuffer:

let bytecode = fetch('templates.gbx')
  .then(req => req.arrayBuffer());