Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
broccoli-asset-rewrite
Advanced tools
broccoli plugin to rewrite a source tree from an asset map.
The broccoli-asset-rewrite npm package is used to rewrite asset URLs in your files. This is particularly useful in build processes where you need to update the paths to assets like images, fonts, and other resources to match the structure of your output directory.
Basic URL Rewriting
This feature allows you to rewrite URLs in specified file types (e.g., HTML, CSS) by prepending a base URL. This is useful for serving assets from a CDN.
const BroccoliAssetRewrite = require('broccoli-asset-rewrite');
let tree = new BroccoliAssetRewrite(inputTree, {
replaceExtensions: ['html', 'css'],
prepend: 'https://cdn.example.com/'
});
Custom Replace Function
This feature allows you to provide a custom replace function to modify URLs in a more flexible way. For example, you can change '/assets/' to '/static/' in your URLs.
const BroccoliAssetRewrite = require('broccoli-asset-rewrite');
let tree = new BroccoliAssetRewrite(inputTree, {
replaceExtensions: ['html', 'css'],
replace: function(url) {
return url.replace('/assets/', '/static/');
}
});
Exclude Specific Files
This feature allows you to exclude specific files from the URL rewriting process. For example, you can exclude 'index.html' from being processed.
const BroccoliAssetRewrite = require('broccoli-asset-rewrite');
let tree = new BroccoliAssetRewrite(inputTree, {
replaceExtensions: ['html', 'css'],
exclude: ['index.html']
});
gulp-rev is a package that allows you to revision static assets by appending content hashes to their filenames. It is similar to broccoli-asset-rewrite in that it helps manage asset URLs, but it focuses more on cache busting through filename changes rather than URL rewriting.
grunt-filerev is a Grunt plugin that renames files based on their content hash. Like broccoli-asset-rewrite, it helps manage asset URLs, but it is more focused on cache busting by changing filenames rather than rewriting URLs within files.
Webpack is a module bundler that can also handle asset management, including URL rewriting and cache busting. It is more comprehensive and complex compared to broccoli-asset-rewrite, offering a wide range of features for modern JavaScript applications.
Broccoli plugin to rewrite a source node from an asset map.
Turns
<script src="assets/appname.js">
background: url('/images/foo.png');
Into
<script src="https://subdomain.cloudfront.net/assets/appname-342b0f87ea609e6d349c7925d86bd597.js">
background: url('https://subdomain.cloudfront.net/images/foo-735d6c098496507e26bb40ecc8c1394d.png');
npm install broccoli-asset-rewrite --save-dev
The asset map should have keys of the original names and values of the new names.
var AssetRewrite = require('broccoli-asset-rewrite');
var generatedMap = {
'assets/appname.css': 'assets/appname-d1d59e0fdcfc183415ab0b72a4f78d9c.css',
'assets/appname.js': 'assets/appname-ed50537fcd5a71113cf79908f49e854d.js',
'assets/vendor.css': 'assets/vendor-d41d8cd98f00b204e9800998ecf8427e.css',
'logo.png': 'logo-c4ab8191636f0a520d1f7f7a82c455a3.png'
};
var assetNode = new AssetRewrite(node, {
assetMap: generatedMap,
replaceExtensions: ['html', 'js', 'css'],
prepend: 'https://subdomain.cloudfront.net/'
});
assetMap
- Default: {}
- The asset map to rewrite source from.replaceExtensions
- Default: ['html', 'css']
- The file types to replace source code with new checksum file names.prepend
- Default: ''
- A string to prepend to all of the assets. Useful for CDN urls like https://subdomain.cloudfront.net/
ignore
- Default: []
- Ignore files from being rewritten.annotation
- Default: null - A human-readable description for this plugin instance.enableCaching
- Default: false - Setting to true will enable caching but may cause problems in typical usage with broccoli-asset-rev.Node 10 or higher
Originally authored by @rickharrison
v3.0.0 (2020-11-30)
FAQs
broccoli plugin to rewrite a source tree from an asset map.
The npm package broccoli-asset-rewrite receives a total of 43,487 weekly downloads. As such, broccoli-asset-rewrite popularity was classified as popular.
We found that broccoli-asset-rewrite demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.