@metrists/webpack

0.0.3 • Public • Published

Metrists webpack 🦿

Simple Localization as a Service


Downloads Per Month Top Language License: MIT <metrists>

Description

The Metrists webpack is a WebPack plugin that helps you include your localization files in your webpack build.

Metrists webpack is intended to be used with a Metrists CLI, and a internationalization library. We highly recommend that you use i18next with Metrists.

Table of Contents

Installation

npm install @metrists/webpack

or using yarn

yarn add @metrists/webpack

Creating a .metristsrc file

The best way to configure Metrists on your repository is to create a .metristsrc file in the root directory of your project. This way this package, and Metrists CLI will reference a single source of truth about your localization.

an example .metristsrc:

{
  "resolvePath": "src/locals",
  "fetcher": "github",
  "envPath": ".env",
  "fetcherParams": {
    "repo": "env.LOCALS_REPO",
    "org": "env.LOCALS_ORG"
  }
}

Differentiating Build Path from Development

By default, Metrists will copy paste the contents of your resolvePath argument in your build folder. If you wish to configure a different route inside the build, you can use the resolvePathBuild parameter, to differentiate your build path:

{
  "resolvePath": "src/locals",
  "resolvePathBuild": "locals",
  "fetcher": "github",
  "envPath": ".env",
  "fetcherParams": {
    "repo": "env.LOCALS_REPO",
    "org": "env.LOCALS_ORG"
  }
}

Webpack Configuration

Once installed, you need use CopyMetristsFiles inside your webpack configuration, as a plugin:

Webpack config file:

const CopyMetristsFiles = require('@metrists/webpack');
// Webpack config object
return {
  plugins: [CopyMetristsFiles()],
};

If you have created and configured your .metristsrc, the plugin will read your configuration and move the file to the correct spot inside the build. If you are not using .metristsrc, you can pass your resolvePath directly to the plugin.

No .metristsrc File

If you wish to not create a .metristsrc configuration file, you can pass a resolvePath and optionally a resolvePathBuild to the plugin directly:

The output of all fetchers should look like this:

const CopyMetristsFiles = require('@metrists/webpack');
// Webpack config object
return {
  plugins: [
    // plugins here...
    CopyMetristsFiles(
      resolvePath: 'src/locals',
      resolvePathBuild : 'locals'
    )
  ],
};

🌕 If you do not pass in a resolvePathBuild to the plugin, the plugin will use resolvePath as the build path too.

Contributing

This package is a beginner-friendly package. If you don't know where to start, visit Make a Pull Request to learn how to make pull requests.

Please visit Contributing for more info.

Code of Conduct

Please visit Code of Conduct.


License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @metrists/webpack

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

23.5 kB

Total Files

28

Last publish

Collaborators

  • parsasi