Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

asset-fingerprint-webpack-rails

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asset-fingerprint-webpack-rails - npm Package Compare versions

Comparing version 0.1.1 to 1.1.1

15

index.js
const fs = require('fs');
function AssetFingerprint(needsFingerprint = true) {
function AssetFingerprint(initializerDirectory, needsFingerprint = true) {
_validateInitializerDirectory();
this.initializerDirectory = initializerDirectory;
this.needsFingerprint = needsFingerprint;
function _validateInitializerDirectory() {
if (initializerDirectory === undefined) {
throw new Error('Please supply a directory path for your initializer, such as `config/initializers`.');
}
}
}

@@ -11,3 +20,5 @@

let output = `ASSET_FINGERPRINT = '${stats.hash}'`;
fs.writeFileSync('config/initializers/asset_fingerprint.rb', output)
let initializerPath = `${this.initializerDirectory}/asset_fingerprint.rb`;
fs.writeFileSync(initializerPath, output);
}

@@ -14,0 +25,0 @@ }.bind(this));

2

package.json
{
"name": "asset-fingerprint-webpack-rails",
"version": "0.1.1",
"version": "1.1.1",
"description": "A webpack plugin to fingerprint your JS for consumption by Rails",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -14,4 +14,11 @@ # Asset Fingerprint Webpack Rails

This plugin assumes you have a `config/initializers` directory in your project. It uses the `hash` values from the webpack `stats` object. This is the value that will be output into a new initializer called `asset_fingerprint.rb`, as: `ASSET_FINGERPRINT=XXXXXXXX`. You should setup your `webpack.config.js` to use this hash when building your output file (see sample config below).
This plugin requires you to set your initializer directory path relative to your webpack config, such as: `config/initializers` as the first argument. The second optional argument determines whether or not the fingerprinting should take place. By default, this is set to `true`.
```javascript
const AssetFingerprintPlugin = require('asset-fingerprint-webpack-rails');
new AssetFingerprintPlugin('config/initializers', true);
```
It uses the `hash` values from the webpack `stats` object. This is the value that will be output into a new initializer called `asset_fingerprint.rb`, as: `ASSET_FINGERPRINT=XXXXXXXX`. You should setup your `webpack.config.js` to use this hash when building your output file (see sample config below).
It is also recommended that you use a plugin such as [clean-webpack-plugin](https://github.com/johnagan/clean-webpack-plugin) in conjunction with this plugin to clean out your output directory on each build, if you wish to avoid a collection of old files.

@@ -30,3 +37,3 @@

const needsFingerprint = someLocalBoolean;
const initializerDirectory = 'config/initializers';
/**

@@ -42,3 +49,3 @@ * add it to your plugins and conditionally use the hash in the filename

plugins: [
new AssetFingerprintPlugin(needsFingerprint)
new AssetFingerprintPlugin(initializerDirectory, needsFingerprint)
]

@@ -75,3 +82,3 @@ };

plugins: [
new AssetFingerprintPlugin()
new AssetFingerprintPlugin(initializerDirectory)
]

@@ -92,3 +99,3 @@ }

### Integration with Rails
Now that our `config/initializers/asset_fingerprint.rb` file is setup, we can conditionally use it in our views by setting up a helper method in `application_helper.rb`:
Now that our `asset_fingerprint.rb` file is setup, we can conditionally use it in our views by setting up a helper method in `application_helper.rb`:

@@ -95,0 +102,0 @@ ```ruby

@@ -6,22 +6,37 @@ describe("AssetFingerprint", function() {

describe("initialization", function() {
it("should default needsFingerprint = true when no args", function() {
fingerprint = new AssetFingerprint();
expect(fingerprint.needsFingerprint).toBeTruthy();
});
describe("needsFingerprint", function() {
it("should default needsFingerprint = true when no args", function() {
fingerprint = new AssetFingerprint('');
expect(fingerprint.needsFingerprint).toBeTruthy();
});
it("should accept true", function() {
fingerprint = new AssetFingerprint(true);
expect(fingerprint.needsFingerprint).toBeTruthy();
});
it("should accept true", function() {
fingerprint = new AssetFingerprint('', true);
expect(fingerprint.needsFingerprint).toBeTruthy();
});
it("should accept false", function() {
fingerprint = new AssetFingerprint(false);
expect(fingerprint.needsFingerprint).toBeFalsy();
it("should accept false", function() {
fingerprint = new AssetFingerprint('', false);
expect(fingerprint.needsFingerprint).toBeFalsy();
});
it("should accept null", function() {
fingerprint = new AssetFingerprint('', null);
expect(fingerprint.needsFingerprint).toBeFalsy();
});
});
it("should accept null", function() {
fingerprint = new AssetFingerprint(null);
expect(fingerprint.needsFingerprint).toBeFalsy();
describe("initializer path", function() {
it("should set when supplied", function() {
var dir = 'config/initializers';
fingerprint = new AssetFingerprint(dir, true);
expect(fingerprint.initializerDirectory).toEqual(dir);
});
it("should fail when not supplied", function() {
fingerprint = function() { new AssetFingerprint(); }
expect(fingerprint).toThrowError('Please supply a directory path for your initializer, such as `config/initializers`.');
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc