Socket
Book a DemoInstallSign in
Socket

assets-to-map-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assets-to-map-webpack-plugin

Append build assets to a mappable file

1.2.5
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Assets to map

A plugin for webpack

npm version Build Status

Summary

Main goal

Extract bundle(s) generated by webpack and add it in a file JSON or YAML or TOML.

What for?

Originally we used it on a Hugo.io project: we needed to inline in a template style and script generated by Webpack. To do so, we decided to go through /Data repertory to access it with Hugo environment variables .Data.

How to use?

Install

$ npm install --save-dev assets-to-map-webpack-plugin
or
$ yarn add -D assets-to-map-webpack-plugin

Implementation

module.exports = {
	// more webpack config
	plugins: [
		new AssetsToMap({
			// options
		})
	]
}

Options

  • sourcePath - {String} (default: "")
    Where to find the assets you need to put in the Json file
  • outputPath - {String} (default: "")
    Where to generate the json file
  • filename - {String} (default: "")
    Name of the destination file. Don't specify the extension.
  • format - {String} (default: "json")
    Possible values:
    • "json"
    • "toml"
    • "yaml" (The format will also defines the extension of the output file)
  • files - {Object} required
    Example: {key: "name"}
    • key will be used as the key in the generated json file
    • name is the name of the bundle you're appending to the generated json file.
  • deleteFiles - {Bool} (default: false)
    allows the plugin to delete source files inlined if true
  • verbose - {Bool} (default: false)

Example

The example below will create a file ./site/data/assets.json containing two keys: css (from the file generated by ExtractTextPlugin) and js, both located in ./site/static. tracking.js will not be included in assets.json for it's not declared in the files option.

const webpack = require("webpack");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
+const AssetsToMap = require('assets-to-map-webpack-plugin');

module.exports = {
    entry: {
        main: [
            "./assets/js/app.js",
            "./assets/css/main.css"
        ],
        tracking: "./assets/js/tracking.js",
    },
    output: {
        path: path.join(__dirname, "site/static"),
        filename: "[name].js"
    },
    module: {
        loaders: [
            // ...
        ]
    },
    plugins: [
        new ExtractTextPlugin("[name].css"),
        // JS optimizations like
        // new UglifyJSPlugin(),
+        new AssetsToMap({
+            sourcePath: "site/static/",
+            outputPath: "site/data/",
+            filename: "assets",
+            files: {
+                css: "main.css",
+                js: "main.js"
+            }
+        }),

    ]
};

FAQs

Package last updated on 13 Mar 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.