forked from redhat-developer/vscode-yaml
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
163 lines (155 loc) · 5 KB
/
webpack.config.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
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
161
162
163
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
//@ts-check
'use strict';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const webpack = require('webpack');
/**@type {import('webpack').Configuration}*/
const config = {
target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
node: {
__dirname: false,
__filename: false,
},
entry: {
extension: './src/node/yamlClientMain.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
languageserver: './node_modules/yaml-language-server/out/server/src/server.js',
},
output: {
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../[resource-path]',
},
devtool: 'source-map',
externals: {
vscode: 'commonjs vscode', // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
prettier: 'commonjs prettier',
},
resolve: {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
},
],
},
{
test: /node_modules[\\|/](vscode-json-languageservice)/,
use: { loader: 'umd-compat-loader' },
},
],
},
};
/**@type {import('webpack').Configuration}*/
const clientWeb = {
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
target: 'webworker', // extensions run in a webworker context
entry: {
'extension-web': './src/webworker/yamlClientMain.ts',
},
output: {
filename: 'extension-web.js',
path: path.join(__dirname, './dist'),
libraryTarget: 'commonjs',
devtoolModuleFilenameTemplate: '../[resource-path]',
},
resolve: {
mainFields: ['module', 'main'],
extensions: ['.ts', '.js'], // support ts-files and js-files
alias: {
'node-fetch': 'whatwg-fetch',
'object-hash': 'object-hash/dist/object_hash.js',
},
fallback: {
path: require.resolve('path-browserify'),
'node-fetch': require.resolve('whatwg-fetch'),
util: require.resolve('util'),
fs: false,
},
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
// configure TypeScript loader:
// * enable sources maps for end-to-end source maps
loader: 'ts-loader',
options: {
compilerOptions: {
sourceMap: true,
declaration: false,
},
},
},
],
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: path.resolve(path.join(__dirname, 'node_modules/process/browser.js')), // provide a shim for the global `process` variable
}),
],
externals: {
vscode: 'commonjs vscode', // ignored because it doesn't exist
},
performance: {
hints: false,
},
devtool: 'nosources-source-map',
};
/**@type {import('webpack').Configuration}*/
const serverWeb = {
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
target: 'webworker', // extensions run in a webworker context
entry: {
'languageserver-web': './node_modules/yaml-language-server/lib/esm/webworker/yamlServerMain',
},
output: {
filename: 'languageserver-web.js',
path: path.join(__dirname, './dist'),
libraryTarget: 'var',
library: 'serverExportVar',
devtoolModuleFilenameTemplate: '../[resource-path]',
},
resolve: {
mainFields: ['browser', 'module', 'main'],
extensions: ['.ts', '.js'], // support ts-files and js-files
alias: {
'./services/yamlFormatter': path.resolve(__dirname, './build/polyfills/yamlFormatter.js'), // not supported for now. prettier can run in the web, but it's a bit more work.
'vscode-json-languageservice/lib/umd': 'vscode-json-languageservice/lib/esm',
},
fallback: {
path: require.resolve('path-browserify/'),
url: require.resolve('url/'),
buffer: require.resolve('buffer/'),
fs: false,
},
},
plugins: [
new webpack.ProvidePlugin({
process: path.resolve(path.join(__dirname, 'node_modules/process/browser.js')), // provide a shim for the global `process` variable
}),
],
module: {},
externals: {},
performance: {
hints: false,
},
devtool: 'nosources-source-map',
};
module.exports = [config, clientWeb, serverWeb];