ttag-webpack-plugin
v0.1.2
Published
> This plugin is an experimental feature, if something goes wrong, still you can use `babel-plugin-ttag` to setup your localization workflow. Follow the doc - https://ttag.js.org/blog/2018/09/05/hardcore-webpack-setup.html
Readme
ttag-webpack-plugin (experimental)
This plugin is an experimental feature, if something goes wrong, still you can use
babel-plugin-ttagto setup your localization workflow. Follow the doc - https://ttag.js.org/blog/2018/09/05/hardcore-webpack-setup.html
ttaglibrary - https://ttag.js.org/ttagandttag-webpack-pluginintegration - https://ttag.js.org/docs/webpack.html
Add this plugin to generate localized build for each locale. This plugin will apply babel-ttag-plugin with appropriate settings for each locale
Works with Webpack4 and Babel7
Installation
npm i -D ttag-webpack-plugin babel-plugin-ttagBasic usage
new TtagPlugin({
translations: {
uk: path.join(__dirname, "./i18n/uk.po")
}
});Options
new TtagPlugin({
translations: {
<locale>: <path to the .po file>
},
filename: '[name].[locale].js',
chunkFilename: '[id].[locale].js',
excludedPlugins: [...],
ttag: <babel-ttag-plugin opts>,
});translations: Map of po files for localesfilename(optional): Output name of localized bundles. (default: '[name]-[locale].js')chunkFilename(optional): Output name of localized chunks. (default: '[id].[name]-[locale].js')excludedPlugins(optional): List of plugins you want to exclude from generating localized bundles.ttag(optional): Possibility to pass some additional opts tottag-webpack-plugin. See all available opts here
Without this plugin
A usual output from webpack output looks like this:

With this plugin
With this plugin added, you will be generating localized outputs:

Example:
const path = require("path");
const TtagPlugin = require("ttag-webpack-plugin");
module.exports = {
entry: {
main: "./src/index.js"
},
module: {
rules: [
{
test: /\.js$/,
use: "babel-loader"
}
]
},
plugins: [
new TtagPlugin({
translations: {
uk: path.join(__dirname, "./i18n/uk.po")
}
})
]
};See example - https://github.com/ttag-org/ttag-webpack-plugin/tree/master/tests-integration/fixtures/example
