forked from microsoft/vscode-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
160 lines (141 loc) · 6.62 KB
/
Copy pathwebpack.config.js
File metadata and controls
160 lines (141 loc) · 6.62 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
//@ts-check
// See https://github.com/Microsoft/vscode-azuretools/wiki/webpack for guidance
'use strict';
const process = require('process');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const StringReplacePlugin = require("string-replace-webpack-plugin");
const dev = require("vscode-azureextensiondev");
let DEBUG_WEBPACK = !!process.env.DEBUG_WEBPACK;
let config = dev.getDefaultWebpackConfig({
projectRoot: __dirname,
verbosity: DEBUG_WEBPACK ? 'debug' : 'normal',
externalNodeModules: [
// Modules that we can't easily webpack for some reason.
// These and their dependencies will be copied into node_modules rather than placed in the bundle
// Keep this list small, because all the subdependencies will also be excluded
// has binary
'win-ca'
],
entries: {
// Note: Each entry is a completely separate Node.js application that cannot interact with any
// of the others, and that individually includes all dependencies necessary (i.e. common
// dependencies will have a copy in each entry file, no sharing).
// Separate module for the language server (doesn't share any code with extension.js)
'./dockerfile-language-server-nodejs/lib/server': './node_modules/dockerfile-language-server-nodejs/lib/server.js'
},
externals:
{
// ./getCoreNodeModule.js (path from keytar.ts) uses a dynamic require which can't be webpacked
'./getCoreNodeModule': 'commonjs getCoreNodeModule',
'win-ca/fallback': 'commonjs win-ca/fallback',
}, // end of externals
loaderRules: [
{
// Fix error:
// > WARNING in ./node_modules/engine.io/lib/server.js 67:43-65
// > Critical dependency: the request of a dependency is an expression
// in this code:
// var WebSocketServer = (this.wsEngine ? require(this.wsEngine) : require('ws')).Server;
test: /engine\.io[/\\]lib[/\\]server.js$/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /var WebSocketServer = \(this.wsEngine \? require\(this\.wsEngine\) : require\('ws'\)\)\.Server;/ig,
replacement: function (match, offset, string) {
// Since we're not using the wsEngine option, we'll just require it to not be set and use only the `require('ws')` call.
return `if (!!this.wsEngine) {
throw new Error('wsEngine option not supported with current webpack settings');
}
var WebSocketServer = require('ws').Server;`;
}
}
]
})
},
{
// Fix warning:
// > WARNING in ./node_modules/cross-spawn/index.js
// > Module not found: Error: Can't resolve 'spawn-sync' in 'C:\Users\<user>\Repos\vscode-cosmosdb\node_modules\cross-spawn'
// > @ ./node_modules/cross-spawn/index.js
// in this code:
// cpSpawnSync = require('spawn-sync'); // eslint-disable-line global-require
test: /cross-spawn[/\\]index\.js$/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /cpSpawnSync = require\('spawn-sync'\);/ig,
replacement: function (match, offset, string) {
// The code in question only applies to Node 0.10 or less (see comments in code), so just throw an error
return `throw new Error("This shouldn't happen"); // MODIFIED`;
}
}
]
})
},
{
// Unpack UMD module headers used in some modules since webpack doesn't
// handle them.
test: /dockerfile-language-service|vscode-languageserver-types/,
use: { loader: 'umd-compat-loader' }
},
{
// Fix error in win-ca: Module parse failed: 'return' outside of function (5:2)
//
// if (process.platform !== 'win32') {
// return; <<<<<<<<<<
// }
test: /win-ca[/\\]lib[/\\]index.js$/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /return;/ig,
replacement: function (match, offset, string) {
return `// Don't need platform check - we do that before calling the module`;
}
}
]
})
},
{
// Fix error in mac-ca: Module parse failed: 'return' outside of function (7:2)
//
// if (process.platform !== 'darwin') {
// module.exports.all = () => [];
// module.exports.each = () => {};
// return; <<<<<<<<<
// }
test: /mac-ca[/\\]index.js$/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /return;/ig,
replacement: function (match, offset, string) {
return `// Don't need platform check - we do that before calling the module`;
}
}
]
})
}
], // end of loaderRules
plugins: [
// Replace vscode-languageserver/lib/files.js with a modified version that doesn't have webpack issues
new webpack.NormalModuleReplacementPlugin(
/[/\\]vscode-languageserver[/\\]lib[/\\]files\.js/,
require.resolve('./build/vscode-languageserver-files-stub.js')
),
// Copy files to dist folder where the runtime can find them
new CopyWebpackPlugin([
// getCoreNodeModule.js -> dist/node_modules/getCoreNodeModule.js
{ from: './out/utils/getCoreNodeModule.js', to: 'node_modules' }
])
]
});
if (DEBUG_WEBPACK) {
console.log('Config:', config);
}
module.exports = config;