๐Ÿ“ฆ microsoft / vscode

๐Ÿ“„ extension.webpack.config.js ยท 70 lines
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/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
// @ts-check
import withDefaults, { nodePlugins } from '../shared.webpack.config.mjs';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import path from 'path';

const isWindows = process.platform === 'win32';
const isMacOS = process.platform === 'darwin';
const isLinux = !isWindows && !isMacOS;

const windowsArches = ['x64'];
const linuxArches = ['x64'];

let platformFolder;
switch (process.platform) {
	case 'win32':
		platformFolder = 'windows';
		break;
	case 'darwin':
		platformFolder = 'macos';
		break;
	case 'linux':
		platformFolder = 'linux';
		break;
	default:
		throw new Error(`Unsupported platform: ${process.platform}`);
}

const arch = process.env.VSCODE_ARCH || process.arch;
console.log(`Building Microsoft Authentication Extension for ${process.platform} (${arch})`);

const plugins = [...nodePlugins(import.meta.dirname)];
if (
	(isWindows && windowsArches.includes(arch)) ||
	isMacOS ||
	(isLinux && linuxArches.includes(arch))
) {
	plugins.push(new CopyWebpackPlugin({
		patterns: [
			{
				// The native files we need to ship with the extension
				from: `**/dist/${platformFolder}/${arch}/(lib|)msal*.(node|dll|dylib|so)`,
				to: '[name][ext]'
			}
		]
	}));
}

export default withDefaults({
	context: import.meta.dirname,
	entry: {
		extension: './src/extension.ts'
	},
	externals: {
		// The @azure/msal-node-runtime package requires this native node module (.node).
		// It is currently only included on Windows, but the package handles unsupported platforms
		// gracefully.
		'./msal-node-runtime': 'commonjs ./msal-node-runtime'
	},
	resolve: {
		alias: {
			'keytar': path.resolve(import.meta.dirname, 'packageMocks', 'keytar', 'index.js')
		}
	},
	plugins
});