|
1 | 1 | /** |
2 | 2 | * @license |
3 | | - * Copyright 2019 Google LLC. All Rights Reserved. |
| 3 | + * Copyright 2020 Google LLC. All Rights Reserved. |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 6 | * You may obtain a copy of the License at |
|
15 | 15 | * ============================================================================= |
16 | 16 | */ |
17 | 17 |
|
18 | | -import node from 'rollup-plugin-node-resolve'; |
19 | | -import typescript from 'rollup-plugin-typescript2'; |
20 | | -import uglify from 'rollup-plugin-uglify'; |
| 18 | +import resolve from '@rollup/plugin-node-resolve'; |
| 19 | +import typescript from '@rollup/plugin-typescript'; |
| 20 | +import {terser} from 'rollup-plugin-terser'; |
| 21 | +import commonjs from '@rollup/plugin-commonjs'; |
21 | 22 |
|
22 | 23 | const PREAMBLE = `/** |
23 | | - * @license |
24 | | - * Copyright ${(new Date).getFullYear()} Google LLC. All Rights Reserved. |
25 | | - * Licensed under the Apache License, Version 2.0 (the "License"); |
26 | | - * you may not use this file except in compliance with the License. |
27 | | - * You may obtain a copy of the License at |
28 | | - * |
29 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
30 | | - * |
31 | | - * Unless required by applicable law or agreed to in writing, software |
32 | | - * distributed under the License is distributed on an "AS IS" BASIS, |
33 | | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
34 | | - * See the License for the specific language governing permissions and |
35 | | - * limitations under the License. |
36 | | - * ============================================================================= |
37 | | - */`; |
| 24 | + * @license |
| 25 | + * Copyright ${(new Date).getFullYear()} Google LLC. All Rights Reserved. |
| 26 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 27 | + * you may not use this file except in compliance with the License. |
| 28 | + * You may obtain a copy of the License at |
| 29 | + * |
| 30 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 31 | + * |
| 32 | + * Unless required by applicable law or agreed to in writing, software |
| 33 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 34 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 35 | + * See the License for the specific language governing permissions and |
| 36 | + * limitations under the License. |
| 37 | + * ============================================================================= |
| 38 | + */`; |
38 | 39 |
|
39 | | -function minify() { |
40 | | - return uglify({output: {preamble: PREAMBLE}}); |
41 | | -} |
| 40 | +function config({ plugins = [], output = {}, tsCompilerOptions = {} }) { |
| 41 | + const defaultTsOptions = { |
| 42 | + include: ['src/**/*.ts'], |
| 43 | + module: 'ES2015', |
| 44 | + }; |
| 45 | + const tsoptions = Object.assign({}, defaultTsOptions, tsCompilerOptions); |
42 | 46 |
|
43 | | -function config({plugins = [], output = {}}) { |
44 | 47 | return { |
45 | 48 | input: 'src/index.ts', |
46 | 49 | plugins: [ |
47 | | - typescript({tsconfigOverride: {compilerOptions: {module: 'ES2015'}}}), |
48 | | - node(), ...plugins |
| 50 | + typescript(tsoptions), |
| 51 | + resolve(), |
| 52 | + commonjs({ |
| 53 | + ignore: ['crypto', 'node-fetch', 'util'], |
| 54 | + include: 'node_modules/**', |
| 55 | + namedExports: { |
| 56 | + './node_modules/seedrandom/index.js': ['alea'], |
| 57 | + }, |
| 58 | + }), |
| 59 | + ...plugins |
49 | 60 | ], |
50 | 61 | output: { |
51 | | - banner: PREAMBLE, |
52 | 62 | sourcemap: true, |
53 | 63 | globals: {'@tensorflow/tfjs': 'tf'}, |
54 | | - ...output |
| 64 | + ...output, |
55 | 65 | }, |
56 | 66 | external: ['@tensorflow/tfjs'] |
57 | 67 | }; |
58 | 68 | } |
59 | 69 |
|
| 70 | +const packageName = 'speechCommands'; |
60 | 71 | export default [ |
| 72 | + config({output: {format: 'umd', name: packageName, file: 'dist/speech-commands.js'}}), |
61 | 73 | config({ |
62 | | - output: |
63 | | - {format: 'umd', name: 'speechCommands', file: 'dist/speech-commands.js'} |
64 | | - }), |
65 | | - config({ |
66 | | - plugins: [minify()], |
67 | | - output: { |
68 | | - format: 'umd', |
69 | | - name: 'speechCommands', |
70 | | - file: 'dist/speech-commands.min.js' |
71 | | - } |
| 74 | + plugins: [terser({output: {preamble: PREAMBLE, comments: false}})], |
| 75 | + output: {format: 'umd', name: packageName, file: 'dist/speech-commands.min.js'} |
72 | 76 | }), |
73 | 77 | config({ |
74 | | - plugins: [minify()], |
| 78 | + plugins: [terser({output: {preamble: PREAMBLE, comments: false}})], |
75 | 79 | output: {format: 'es', file: 'dist/speech-commands.esm.js'} |
76 | 80 | }) |
77 | 81 | ]; |
0 commit comments