-
Notifications
You must be signed in to change notification settings - Fork 69
/
webpack.config.views.js
116 lines (113 loc) · 3.93 KB
/
webpack.config.views.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
#!/usr/bin/env node
/* 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',
},
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: 'es2022',
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
},
};
};