Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
assets-webpack-plugin
Advanced tools
The assets-webpack-plugin is a Webpack plugin that generates a JSON file containing the paths of the output files. This is useful for server-side rendering or when you need to inject the assets into your HTML manually.
Generate JSON file with asset paths
This feature allows you to generate a JSON file that contains the paths of the output files. This is useful for server-side rendering or when you need to inject the assets into your HTML manually.
const AssetsWebpackPlugin = require('assets-webpack-plugin');
module.exports = {
// other webpack configuration
plugins: [
new AssetsWebpackPlugin({
path: path.join(__dirname, 'dist'),
filename: 'assets.json'
})
]
};
Customizing the output format
This feature allows you to customize the format of the generated JSON file. For example, you can enable pretty printing to make the JSON file more readable.
const AssetsWebpackPlugin = require('assets-webpack-plugin');
module.exports = {
// other webpack configuration
plugins: [
new AssetsWebpackPlugin({
path: path.join(__dirname, 'dist'),
filename: 'assets.json',
prettyPrint: true
})
]
};
Including additional information
This feature allows you to include additional information in the generated JSON file. For example, you can specify which file types to include in the JSON file.
const AssetsWebpackPlugin = require('assets-webpack-plugin');
module.exports = {
// other webpack configuration
plugins: [
new AssetsWebpackPlugin({
path: path.join(__dirname, 'dist'),
filename: 'assets.json',
includeAllFileTypes: false,
fileTypes: ['js', 'css']
})
]
};
The html-webpack-plugin simplifies the creation of HTML files to serve your webpack bundles. It automatically injects the output files into the HTML file. Unlike assets-webpack-plugin, which generates a JSON file with asset paths, html-webpack-plugin directly creates an HTML file with the necessary script and link tags.
The webpack-manifest-plugin generates a manifest file that maps the original filenames to the hashed filenames. This is similar to assets-webpack-plugin, but it focuses on creating a manifest file for cache busting and long-term caching.
The webpack-assets-manifest plugin generates a JSON file that maps the original filenames to the hashed filenames, similar to assets-webpack-plugin. However, it provides more customization options and supports merging with existing manifest files.
Webpack plugin that emits a json file with assets paths.
When working with Webpack will probably want to generate you bundles with a generate hash in them (for cache busting).
This plug-in generates a json file with the generated assets to be used somewhere else, I use this with Rails so it can find the assets.
npm install assets-webpack-plugin --save
In you webpack config include the plug-in. And add it to your config:
var path = require("path");
var SaveAssetsJson = require('assets-webpack-plugin');
module.exports = {
...
output: {
path: path.join(__dirname, "public", "js"),
filename: "[name]-bundle-[hash].js",
publicPath: "/js/"
},
....
plugins: [new SaveAssetsJson()]
};
You can pass the following options:
path:
Path where to save the created json file. Defaults to the current directory.
new SaveHashes({path: path.join(__dirname, 'app', 'views')})
filename:
Name for the created json file. Defaults to webpack-assets.json
new SaveHashes({filename: 'assets.json'})
I use this with Rails, so it can find my Webpack assets. In my application controller I have:
def script_for(bundle)
path = Rails.root.join('app', 'views', 'webpack-assets.json') # This is the file generated by the plug-in
file = File.read(path)
json = JSON.parse(file)
json[bundle]
end
Then in the actions:
def show
@script = script_for('clients') # this will retrive the bundle named 'clients'
end
And finally in the views:
<div id="app">
<script src="<%= @script %>"></script>
</div>
npm test
FAQs
Emits a json file with assets paths
The npm package assets-webpack-plugin receives a total of 223,026 weekly downloads. As such, assets-webpack-plugin popularity was classified as popular.
We found that assets-webpack-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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.