forked from hardisgroupcom/vscode-sfdx-hardis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.common.js
More file actions
199 lines (195 loc) · 5.02 KB
/
webpack.common.js
File metadata and controls
199 lines (195 loc) · 5.02 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const path = require("path");
const webpack = require("webpack");
const LwcWebpackPlugin = require("lwc-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const extensionConfig = {
target: "node",
entry: "./src/extension.ts",
output: {
path: path.resolve(__dirname, "out"),
filename: "extension.js",
libraryTarget: "commonjs2",
},
externals: {
vscode: "commonjs vscode",
},
resolve: {
extensions: [".ts", ".js"],
},
module: {
rules: [
// Prevent webpack from trying to parse TypeScript declaration files
// which may be present in node_modules and are not valid runtime
// modules.
{
test: /\.d\.ts$/,
type: "asset/source",
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
},
],
},
],
},
};
const workerConfig = {
target: "node",
entry: "./src/worker.ts",
output: {
path: path.resolve(__dirname, "out"),
filename: "worker.js",
libraryTarget: "commonjs2",
},
externals: {
vscode: "commonjs vscode",
},
resolve: {
extensions: [".ts", ".js"],
},
module: {
rules: [
// Prevent webpack from trying to parse TypeScript declaration files
// which may be present in node_modules and are not valid runtime
// modules.
{
test: /\.d\.ts$/,
type: "asset/source",
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
},
],
},
],
},
};
const lwcWebviewConfig = {
target: "web",
entry: "./src/webviews/lwc-ui/index.js",
output: {
path: path.resolve(__dirname, "out", "webviews"),
filename: "lwc-ui.js",
},
resolve: {
// Only resolve JS files for the webview bundle. Resolving .ts here makes
// webpack attempt to load .d.ts declaration files from node_modules
// which are not valid modules for the web target and cause parse errors.
extensions: [".js"],
modules: ["node_modules"],
fallback: {
process: require.resolve("process/browser"),
},
},
module: {
rules: [
// Treat TypeScript declaration files as raw source so webpack does not
// attempt to parse them as JS modules. Some node modules include .d.ts
// files in runtime directories which can otherwise be pulled into the
// bundle by dynamic requires.
{
test: /\.d\.ts$/,
type: "asset/source",
},
{
test: /\.js$/,
include: [
path.resolve(__dirname, "src/webviews/lwc-ui"),
path.resolve(__dirname, "src/webviews"),
],
use: [
{
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
plugins: [
[
"@lwc/babel-plugin-component",
{
namespace: "s",
experimentalDynamicComponent: true,
enableDynamicComponents: true,
},
],
],
},
},
],
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: "process/browser",
}),
new LwcWebpackPlugin({
modules: [
{
dir: path.resolve(__dirname, "src/webviews/lwc-ui/modules"),
},
{
npm: "lightning-base-components",
},
],
experimentalSyntheticShadow: true,
experimentalDynamicComponent: true,
enableDynamicComponents: true,
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(
__dirname,
"node_modules/@salesforce-ux/design-system/assets/styles/salesforce-lightning-design-system.min.css",
),
to: path.resolve(
__dirname,
"out/assets/styles/salesforce-lightning-design-system.min.css",
),
noErrorOnMissing: true,
},
{
from: path.resolve(
__dirname,
"node_modules/@salesforce-ux/design-system/assets/icons",
),
to: path.resolve(__dirname, "out/assets/icons"),
noErrorOnMissing: true,
},
{
from: path.resolve(
__dirname,
"node_modules/mermaid/dist/mermaid.min.js",
),
to: path.resolve(__dirname, "out/webviews"),
noErrorOnMissing: true,
},
{
from: path.resolve(__dirname, "resources/webviews"),
to: path.resolve(__dirname, "out/resources/webviews"),
noErrorOnMissing: true,
},
{
from: path.resolve(
__dirname,
"resources/sfdx-hardis.jsonschema.json",
),
to: path.resolve(
__dirname,
"out/resources/sfdx-hardis.jsonschema.json",
),
noErrorOnMissing: true,
},
],
}),
],
};
module.exports = { extensionConfig, workerConfig, lwcWebviewConfig };