-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.build.js
93 lines (84 loc) · 3.17 KB
/
webpack.config.build.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
81
82
83
84
85
86
87
88
89
90
91
92
93
/* eslint-disable class-methods-use-this */
const path = require('path');
const fs = require('fs');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
class TrickLernaPlugin {
apply(compiler) {
const isDirectory = (source) => fs.lstatSync(source).isDirectory();
const getDirectories = (source) =>
fs
.readdirSync(source)
.map((name) => path.join(source, name))
.filter(isDirectory);
compiler.hooks.done.tap('TrickLernaPlugin', (stats /* stats is passed as an argument when done hook is tapped. */) => {
try {
const CDK_OUT_DIR = path.join(__dirname, './packages/cdk-app/cdk.out');
getDirectories(CDK_OUT_DIR).forEach((dir) => {
const PACKAGE_JSON_FILE_PATH = path.join(dir, 'package.json');
if (fs.existsSync(PACKAGE_JSON_FILE_PATH)) {
const packageJsonOriginalContents = require(PACKAGE_JSON_FILE_PATH);
if (!packageJsonOriginalContents.name.includes('compiled')) {
const packageJsonContents = JSON.stringify({
version: packageJsonOriginalContents.version,
name: `${packageJsonOriginalContents.name}-compiled`,
});
fs.writeFileSync(PACKAGE_JSON_FILE_PATH, packageJsonContents);
}
}
});
} catch (err) {
// console.log(err)
}
});
}
}
// const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
module.exports = (dirname) => {
const SOURCE_DIR = path.join(dirname, './src/');
const TARGET_DIR = path.join(dirname, './dist/');
const filename = 'index.js';
const entry = path.join(SOURCE_DIR, 'index.ts');
const plugins = [];
plugins.push(new TrickLernaPlugin());
return {
mode: 'production',
devtool: 'source-map',
entry,
target: 'node',
resolve: {
extensions: ['.mjs', '.ts', '.js'],
plugins: [
new TsconfigPathsPlugin({
/* options: see below */
}),
],
},
output: {
libraryTarget: 'commonjs2',
path: TARGET_DIR,
filename,
},
// externals: [],
module: {
rules: [
{
test: /.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
configFile: path.join(dirname, 'tsconfig.build.json'),
},
},
],
},
],
},
plugins,
externals: [{ 'aws-sdk': 'commonjs aws-sdk' }],
optimization: {
minimize: false,
// Turned this off because it apollo server throws error, schema must contain uniquely named types but contains multiple types named "XXX"
},
};
};