forked from ember-tooling/ember-language-server
-
Notifications
You must be signed in to change notification settings - Fork 16
/
webpack.config.js
139 lines (130 loc) · 3.58 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
'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 NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const isCI = process.env.CI;
const buildName = process.env.npm_lifecycle_event;
// build:bundle:node
// console.log(process.env.npm_lifecycle_event);
/**@type {import('webpack').Configuration}*/
const nodeBundleConfig = {
mode: 'production',
devtool: 'source-map',
target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
entry: './src/server.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
output: {
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
path: path.join(__dirname, 'dist', 'bundled'),
filename: 'node-server.js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../[resource-path]',
},
// devtool: 'source-map',
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
},
],
},
],
},
resolve: {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
mainFields: ['module', 'main'],
extensions: ['.ts', '.js'], // support ts-files and js-files
},
};
const workerBundleConfig = /** @type WebpackConfig */ {
mode: 'production',
target: 'webworker', // web extensions run in a webworker context
entry: {
'start-worker-server': './src/start-worker-server.ts',
},
output: {
filename: 'start-worker-server.js',
path: path.join(__dirname, 'dist', 'bundled'),
libraryTarget: 'var',
library: 'serverExportVar',
},
plugins: isCI
? [
new NodePolyfillPlugin({
// excludeAliases: ["console"]
excludeAliases: [],
}),
]
: [
new BundleAnalyzerPlugin(),
new NodePolyfillPlugin({
// excludeAliases: ["console"]
excludeAliases: [],
}),
],
resolve: {
mainFields: ['module', 'main'],
extensions: ['.ts', '.js'], // support ts-files and js-files
alias: {
'find-up': false,
'dag-map': false,
'ember-template-recast': false,
// 'caniuse-lite': false,
// assert: false,
// buffer: false,
browserlist: false,
'@babel/generator': false,
'@babel/highlight': false,
// '@babel/types': false,
// 'babel-types': false,
},
fallback: {
// path: require.resolve("path-browserify"),
// util: false,
// os: false,
fs: false,
// browserlist: false,
// tty: false,
// assert: false,
debug: false,
net: false,
// stream: false,
},
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
},
],
},
],
},
externals: {
vscode: 'commonjs vscode', // ignored because it doesn't exist
},
performance: {
hints: false,
},
// devtool: 'source-map',
};
const configs = [
{
name: 'build:bundle:node',
config: nodeBundleConfig,
},
{
name: 'build:bundle:worker',
config: workerBundleConfig,
},
];
module.exports = configs.filter(({ name }) => name.startsWith(buildName)).map((e) => e.config);