4.0.1 • Published 3 years ago

@hdsydsvenskan/asset-versions v4.0.1

Weekly downloads
227
License
MIT
Repository
github
Last release
3 years ago

Asset Versions

CLI and helper methods for asset versioning. Includes support for Webpack chunking.

Installation

npm install --save-dev @hdsydsvenskan/asset-versions

Release new version

Follow Semantic Versioning and use np and a version like patch | minor | major | prepatch | preminor | premajor | prerelease | 1.2.3

np patch

Example

See a full example, including Webpack support, in example/ folder and/or run the start npm script (run yarn start / npm start).

Usage

Generate asset version through CLI

  1. Add an assets.json
  2. Run asset-versions
  3. Get an assets-versioned.json file

Programmaticly access versioned paths

const AssetVersions = require('@hdsydsvenskan/asset-versions');

const assets = new AssetVersions({
  assetDefinitions: __dirname + '/assets.json'
});

// Returns something like 'assets/rev/main-e508b3af03.css'
assets.getAssetPath('assets/main.css');

Or, in case of code splitted javascript (likely through the use of Webpack):

// Returns something like ['assets/rev/main-e508b3af03.js', 'assets/rev/vendor-abc123.js']
assets.getAssetPathWithDependencies('assets/main.js');

Configure asset versions

Create a assets.json file:

{
  "sourceDir": "assets",
  "targetDir": "assets/rev/",
  "files": [
    "main.css",
    "main-dev.css",
    "main.js"
  ]
}

Configuration options

  • versions file name – both the cli (through the --output/ -o flag) and the module (through the versionsFileName option) can be tweaked to use another versions file than the default asset-versions.json

Extras

  • AssetVersions.baseAppPlugin – for use with @hdsydsvenskan/base-web-app
  • AssetVersions.webpackManifestPluginGenerate – a generate method for use with webpack-manifest-plugin to generate manifest with dependencies
5.0.1-1

3 years ago

5.0.0-0

3 years ago

5.0.1-0

3 years ago

4.0.1

4 years ago

4.0.0

4 years ago

4.0.0-1

4 years ago

4.0.0-0

4 years ago

3.1.2-0

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.0

5 years ago

2.0.0

5 years ago

1.5.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago