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

grunt-assets-version-replace

v0.2.4

Published

Generate and replace static assets version with Grunt

Downloads

17

Readme

grunt-assets-version-replace Build Status npm version

Gulp version is here

中文文档

Grunt plugin for managing version of assets, easy to build new version to commit and deploy.

Features

  • Generate file version by timestamp
  • Auto replace versioned assets in template files, like php, python Django, Expressjs ejs and etc.

Example

1. Your assets files

Assets structure:

js_build/app.js
css_build/webapp.css

Files under js_build and css_build are generated by compass uglify

Links in templates:

<link href="static/dist/css_build/app.auto_create_ts_000.css" />
<link href="static/dist/css_build/desktop.auto_create_ts_000.css" />

Note: auto_create_ts_000 is a placeholder for replacing with generated versions

2. Configs in Gruntfile.js:

grunt.initConfig({
  assets_version_replace: {
    commons: {
      tsFiles: ['test/css_build/*.css', 'test/js_build/*.js'],
      tsPrefix: 'common_auto_create_ts_',
      tsVersionedFilesDest: 'test/dist/',
      replaceTemplateList: [
        'test/header.php',
        'test/footer.php',
        'test/submodule/header.php',
      ],
    }
  }
})

3. Run grunt task

grunt assets_version_replace in your terminal.

Your get these result:

  • Files named with generated version
dest/js_build/app.auto_create_ts_1421999411.js
dest/css_build/webapp.auto_create_ts_1421999411.css
  • LInks in template have been replaced with generated version
<link href="static/dist/css_build/app.auto_create_ts_1421999411.css" />
<link href="static/dist/css_build/desktop.auto_create_ts_1421999411.css" />

4. Commit these build assets and changes in template file

Install

npm install grunt-assets-version-replace --save-dev

In your Gruntfile.js place this line:

grunt.loadNpmTasks('grunt-assets-version-replace');

Form asset link as below in your template:

<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <title>test</title>
  <link href="static/dist/css_build/app.auto_create_ts_000.css" />
  <link href="static/dist/css_build/desktop.auto_create_ts_000.css" />
</head>
<body>

Notes:

  • auto_create_ts_000 is a placeholder for replacing with generated versions
  • auto_create_ts_ is prefix see document

Grunt Plugin Options

options.tsFiles

Array of globs. Files which will be copied to a new folder and named with gerenated version.

Type: Array Default value: []

options.tsPrefix

Prefix of gerenated version. E.g. prefix taobao_new_home_auto_create_ts_ will get result files like this taobao_new_home_auto_create_ts_1421999411.js

Generally no need to config it excerpt there is conflict in your code.

Type: String Default value: auto_create_ts_

options.tsVersionedFilesDest

The destination folder place the result files.

Type: Array Default value: []

options.replaceTemplateList

List of templates which contain assets links of tsFiles . Support whatever extension like php, python Django, Express and etc.

Type: Array Default value: []

Release History

  • 2015-12-14 v0.2.3 Update readme
  • 2015-12-13 v0.2.2 Update github repo link
  • 2015-03-03 v0.2.1 Fix typo
  • 2015-02-06 v0.2.0 Migrate and refactor
  • 2015-01-06 v0.1.0 Initial commit