1 |
|
2 |
|
3 | import * as p from 'path';
|
4 | import * as fs from 'fs';
|
5 | import {rollup} from 'rollup';
|
6 | import babel from 'rollup-plugin-babel';
|
7 | import commonjs from 'rollup-plugin-commonjs';
|
8 | import uglify from 'rollup-plugin-uglify';
|
9 |
|
10 | const isProduction = process.env.NODE_ENV === 'production';
|
11 |
|
12 | const entry = p.resolve('src/browser-main.js');
|
13 | const dest = p.resolve(`dist/Intl.${isProduction ? 'min.js' : 'js'}`);
|
14 |
|
15 | const bundleConfig = {
|
16 | dest,
|
17 | format: 'umd',
|
18 | moduleName: 'IntlPolyfill',
|
19 | sourceMap: true,
|
20 | external: ['Intl'],
|
21 | };
|
22 |
|
23 | let babelConfig = JSON.parse(fs.readFileSync('src/.babelrc', 'utf8'));
|
24 | babelConfig.babelrc = false;
|
25 | babelConfig.presets = babelConfig.presets.map((preset) => {
|
26 | return preset === 'es2015' ? 'es2015-rollup' : preset;
|
27 | });
|
28 |
|
29 | let plugins = [
|
30 | babel(babelConfig),
|
31 | commonjs({
|
32 | sourceMap: true,
|
33 | }),
|
34 | ];
|
35 |
|
36 | if (isProduction) {
|
37 | plugins.push(
|
38 | uglify({
|
39 | warnings: false,
|
40 | })
|
41 | );
|
42 | }
|
43 |
|
44 | let bundle = Promise.resolve(rollup({entry, plugins}));
|
45 | bundle.then(({write}) => write(bundleConfig)).then(() => {
|
46 |
|
47 |
|
48 | const lib = fs.readFileSync(dest);
|
49 | const complete = fs.readFileSync(p.resolve('locale-data/complete.js'));
|
50 | fs.writeFileSync(p.resolve('dist/Intl.complete.js'), `${lib}\n${complete}`);
|
51 |
|
52 | });
|
53 |
|
54 | process.on('unhandledRejection', (reason) => {throw reason;});
|