-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathwebpack.config.views.js
More file actions
130 lines (125 loc) · 4.56 KB
/
webpack.config.views.js
File metadata and controls
130 lines (125 loc) · 4.56 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
#!/usr/bin/env node
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/* eslint-env node */
const path = require('path');
const webpack = require('webpack');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = (env, { mode }) => {
const isDev = mode === 'development';
return {
// stats: 'detailed',
target: 'web',
mode: mode || 'none',
entry: {
views: './src/webviews/index.tsx',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'module',
},
cache: {
type: 'filesystem',
name: `views-build${isDev ? '-dev' : ''}`,
cacheDirectory: path.resolve(__dirname, 'node_modules/.cache/webpack/views'),
buildDependencies: {
config: [__filename],
},
},
experiments: {
outputModule: true,
},
resolve: {
roots: [__dirname],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
module: {
rules: [
{
test: /\.(tsx?)?$/iu,
use: {
loader: 'swc-loader',
options: {
module: {
type: 'es6',
},
isModule: true,
sourceMaps: isDev,
jsc: {
keepClassNames: true,
target: 'es2023',
parser: {
syntax: 'typescript',
tsx: true,
},
},
},
},
exclude: /node_modules/u,
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
'style-loader',
// Translates CSS into CommonJS
'css-loader',
// Compiles Sass to CSS
'sass-loader',
],
},
{
test: /\.ttf$/,
type: 'asset/resource',
},
],
},
devServer: {
static: {
directory: path.join(__dirname, 'src/webviews/static'),
publicPath: '/static',
},
allowedHosts: 'all',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
},
hot: true,
host: '127.0.0.1',
client: {
overlay: true,
},
compress: true,
port: 18080,
webSocketServer: 'ws',
},
plugins: [
//new BundleAnalyzerPlugin(),
new MonacoWebpackPlugin({ languages: ['sql', 'json'] }),
new webpack.ProvidePlugin({ React: 'react' }),
isDev && new webpack.HotModuleReplacementPlugin(),
isDev && new ReactRefreshWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [{ from: 'src/webviews/static', to: 'static', noErrorOnMissing: true }].filter(Boolean),
}),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
],
devtool: isDev ? 'source-map' : false,
infrastructureLogging: {
level: 'log', // enables logging required for problem matchers
},
};
};