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

rails-manifest-plugin

v1.0.0

Published

A webpack plugin for generating a Rails manifest.json file for the compiled assets.

Downloads

504

Readme

Rails Manifest Plugin

A webpack plugin for generating a Rails manifest.json file for the compiled assets.

Installation

Install via npm:

$ npm install rails-manifest-plugin --save-dev

Usage

Add to your production webpack config:

{
  plugins: [
    new RailsManifestPlugin()
  ]
}

Deploying to Heroku

We deploy almost all of our Rails apps to Heroku. Here's a glimpse at our setup:

Buildpacks

  • heroku/nodejs
  • heroku/ruby

Webpack Config

The file config/webpack/production.js contains our webpack config for production. MD5 hashes are appended to all asset file names, which is why we need this plugin to generate the manifest.json file.

Much of the webpack config changes from one project to another, but pretty much all of our Rails projects have this in common in the webpack production config files:

var appRoot = require('app-root-path') + '';
var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
  module: {
    loaders: [{
      test:    /\.(gif|png|jpe?g|svg)$/i,
      loaders: ['file?name=images/[name]-[hash].[ext]', 'image-webpack']
    }, {
      test:    /\.scss$/,
      loader:  ExtractTextPlugin.extract(['css?sourceMap', 'resolve-url', 'sass?sourceMap'])
    }]
  },

  output: {
    chunkFilename: 'javascripts/chunk.[id]-[hash].js',
    filename:      'javascripts/[name]-[hash].js',
    path:          path.join(appRoot, 'public', 'assets'),
    publicPath:    '/assets/'
  },

  plugins: [
    // Extract CSS to its own file(s)
    new ExtractTextPlugin('stylesheets/[name]-[hash].css'),

    // Create the manifest.json file so Rails can find the assets
    new RailsManifestPlugin()
  ],
};

Build Script

We add the Heroku heroku-postbuild script to our package.json file to compile all assets with webpack and generate the manfest.json file. Heroku's Ruby buildpack will pick up the manfest.json file and assume all assets have already been compiled.

{
  "scripts": {
    "heroku-postbuild": "rm -rf public/assets && bower install && webpack --config config/webpack/production.js"
  }
}

Heroku Config Variables

We install all webpack packages as development dependencies in order to more easily keep track of our app's depencencies, so we need Herokku's nodejs buildpack to install dev dependencies so webpack can compile the assets. This is done by setting the config variable NPM_CONFIG_PRODUCTION to false.

NPM_CONFIG_PRODUCTION=false