Repository navigation
Expand file tree
/
Copy pathwebpack.main.config.ts
More file actions
54 lines (48 loc) · 1.79 KB
/
Copy pathwebpack.main.config.ts
File metadata and controls
54 lines (48 loc) · 1.79 KB
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
import type { Configuration } from 'webpack';
import * as fs from 'fs';
import * as path from 'path';
import { rules } from './webpack.rules';
import { plugins } from './webpack.plugins';
class CopyNodePtyPrebuildsPlugin {
apply(compiler: any): void {
compiler.hooks.afterEmit.tap('CopyNodePtyPrebuildsPlugin', () => {
const outputPath = compiler.options.output?.path;
if (!outputPath) {
return;
}
const arch = process.arch;
const moduleRoot = path.resolve(__dirname, 'node_modules', 'node-pty');
const prebuildSourceDir = path.resolve(moduleRoot, 'prebuilds', `darwin-${arch}`);
const prebuildTargetDir = path.resolve(outputPath, 'prebuilds', `darwin-${arch}`);
if (fs.existsSync(prebuildSourceDir)) {
fs.mkdirSync(prebuildTargetDir, { recursive: true });
fs.cpSync(prebuildSourceDir, prebuildTargetDir, { recursive: true });
}
const releaseSourceDir = path.resolve(moduleRoot, 'build', 'Release');
const releaseTargetDir = path.resolve(outputPath, 'build', 'Release');
if (fs.existsSync(releaseSourceDir)) {
fs.mkdirSync(releaseTargetDir, { recursive: true });
for (const fileName of ['pty.node', 'spawn-helper']) {
const src = path.resolve(releaseSourceDir, fileName);
const dst = path.resolve(releaseTargetDir, fileName);
if (fs.existsSync(src)) {
fs.copyFileSync(src, dst);
if (fileName === 'spawn-helper') {
fs.chmodSync(dst, 0o755);
}
}
}
}
});
}
}
export const mainConfig: Configuration = {
entry: './src/index.ts',
module: {
rules,
},
plugins: [...plugins, new CopyNodePtyPrebuildsPlugin()],
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json'],
},
};