UNPKG

2.98 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const globby = require("globby");
4const pathJs = require("path");
5const webpack = require("webpack");
6function transpileFunctions(entriesPath, distPath) {
7 return new Promise((resolve, reject) => {
8 // Note: it works because we have client.ts present
9 globby([`${entriesPath}/*.ts`])
10 .then(files => {
11 if (files.length) {
12 const entries = files.reduceRight((entriesAcc, file) => (Object.assign({}, entriesAcc, { [pathJs.basename(file).split('.')[0]]: file })), {});
13 webpack({
14 mode: 'production',
15 // optimization: {
16 // minimize: false
17 // },
18 entry: entries,
19 module: {
20 rules: [
21 {
22 test: /\.tsx?$/,
23 loader: 'ts-loader',
24 exclude: /node_modules/,
25 options: {
26 onlyCompileBundledFiles: true,
27 compilerOptions: {
28 allowUnreachableCode: false,
29 declaration: false,
30 lib: ['es2017'],
31 noUnusedLocals: false,
32 noUnusedParameters: false,
33 allowSyntheticDefaultImports: true,
34 experimentalDecorators: true,
35 moduleResolution: 'node',
36 module: 'es6',
37 target: 'es2017'
38 }
39 }
40 }
41 ]
42 },
43 resolve: {
44 extensions: ['.tsx', '.ts', '.js', '.json']
45 },
46 target: 'node',
47 output: {
48 libraryTarget: 'commonjs2',
49 filename: '[name].js',
50 path: distPath
51 }
52 // TODO: check if it is necessary
53 // context: pathJs.resolve(path)
54 }, (err, stats) => {
55 if (err || stats.hasErrors()) {
56 reject(stats);
57 }
58 else {
59 resolve(true);
60 }
61 });
62 }
63 else {
64 reject([{ error: 'No functions to process' }]);
65 }
66 })
67 .catch(error => {
68 reject([{ error }]);
69 });
70 });
71}
72exports.transpileFunctions = transpileFunctions;