New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

webpack-json-bundler-plugin

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-json-bundler-plugin

A webpack plugin to bundle json files together

  • 1.1.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
170
decreased by-27.04%
Maintainers
2
Weekly downloads
 
Created
Source

webpack-json-builder-plugin

A webpack plugin that can be used to bundle JSON files containing locale information by name

To install:

$ npm install --save webpack-json-bundler-plugin

Use Case

Imagine having a React application. Each component will need to define strings for its user interface. If these components should be multilingual, you will need locale files.

Using a directory layout like this:

src/
  components/
    component-1/
      locales/
        de-de.json
        en-us.json
      component-1.js
      component-1.scss
    component-2/
      locales/
        de-de.json
        fr-fr.json
      component-2.js
      component-2.scss
dist/
  locales/
    de-de.json
    en-us.json
    fr-fr.json
  app.js

In our build process, we want to merge all language files for each language together. E.g. component-1/locales/de-de.json and component-2/locales/de-de.json will be merged into a single file de-de.json, with their contents available as properties derivered from the file path.

The content of component-1/locales/de-de.json will be available as the deep property components.component-1 inside the bundle de-de.json file.

Example

In your webpack.config.js:

var JsonBundlerPlugin = require('webpack-json-bundler-plugin');

module.exports = {
  // ...

  plugins: [
    new JSONBundlerPlugin({
      fileInput: '**/locales/*.json',
		  omit: /\/locales|\/?components|\/?services|\/?scenes|\/?features/g,
		  rootDirectory: 'src',
      localeDirectory: 'locales/'
    }),
  ]

}

Options

You can pass the following options as parameters.

  • omit - a regular expression describing which directories to omit from the locale path in the bundled JSON

Example: dir1/dir2/components/dir3 if 'omit' = //?components/g the resulting locale path in your bundled JSON will be dir1/dir2/dir3

  • fileInput - a string that is used to identify all locale files that you wish to include in your bundled JSON.

  • localeDirectory - the directory in which you want webpack to put the newly created locale files.

Example: if localeDirectory: 'locales/' You will find your locale files in the locale folder within the directory where your webpack bundle is being output ex. 'dist/locales/fr-FR.json ...

  • rootDirectory - the uppermost directory within your project where all locale files can be found. In the example project structure above, this would be 'src'.

FAQs

Package last updated on 08 Dec 2017

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

  • 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