forked from mozilla/addons-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.l10n.config.babel.js
80 lines (70 loc) · 2.45 KB
/
webpack.l10n.config.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* eslint-disable no-console, import/no-extraneous-dependencies */
import fs from 'fs';
import chalk from 'chalk';
import config from 'config';
import webpack from 'webpack';
import { getRules } from './webpack-common';
import webpackConfig from './webpack.prod.config.babel';
const appName = config.get('appName');
if (!appName) {
console.log(chalk.red('Please specify the appName with NODE_APP_INSTANCE'));
process.exit(1);
}
if (process.env.NODE_ENV !== 'production') {
console.log(chalk.red('This should be run with NODE_ENV="production"'));
process.exit(1);
}
const babelrc = fs.readFileSync('./.babelrc');
const babelrcObject = JSON.parse(babelrc);
const babelPlugins = babelrcObject.plugins || [];
// Create UTC creation date in the correct format.
const potCreationDate = new Date()
.toISOString()
.replace('T', ' ')
.replace(/:\d{2}.\d{3}Z/, '+0000');
const babelL10nPlugins = [
[
'module:babel-gettext-extractor',
{
headers: {
'Project-Id-Version': appName,
'Report-Msgid-Bugs-To': 'EMAIL@ADDRESS',
'POT-Creation-Date': potCreationDate,
'PO-Revision-Date': 'YEAR-MO-DA HO:MI+ZONE',
'Last-Translator': 'FULL NAME <EMAIL@ADDRESS>',
'Language-Team': 'LANGUAGE <[email protected]>',
'MIME-Version': '1.0',
'Content-Type': 'text/plain; charset=utf-8',
'Content-Transfer-Encoding': '8bit',
'plural-forms': 'nplurals=2; plural=(n!=1);',
},
functionNames: {
gettext: ['msgid'],
dgettext: ['domain', 'msgid'],
ngettext: ['msgid', 'msgid_plural', 'count'],
dngettext: ['domain', 'msgid', 'msgid_plural', 'count'],
pgettext: ['msgctxt', 'msgid'],
dpgettext: ['domain', 'msgctxt', 'msgid'],
npgettext: ['msgctxt', 'msgid', 'msgid_plural', 'count'],
dnpgettext: ['domain', 'msgctxt', 'msgid', 'msgid_plural', 'count'],
},
fileName: `locale/templates/LC_MESSAGES/${appName}.pot`,
baseDirectory: process.cwd(),
stripTemplateLiteralIndent: true,
},
],
];
const babelOptions = Object.assign({}, babelrcObject, {
plugins: babelPlugins.concat(babelL10nPlugins),
});
export default Object.assign({}, webpackConfig, {
entry: { [appName]: `${appName}/client` },
module: {
rules: getRules({ babelOptions }),
},
plugins: [
// Don't generate modules for locale files.
new webpack.IgnorePlugin(new RegExp(`locale\\/.*\\/${appName}\\.js$`)),
...webpackConfig.plugins,
],
});