-
Notifications
You must be signed in to change notification settings - Fork 155
/
webpack.config.js
102 lines (94 loc) · 2.69 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
const path = require('path');
const fs = require('fs-extra');
const CopyWebpackPlugin = require('copy-webpack-plugin');
// variables
const isProduction = process.argv.indexOf('-p') >= 0;
const browserSourcePath = path.join(__dirname, './browser/src');
const serverSourcePath = path.join(__dirname, './src');
const outPath = path.join(__dirname, './dist');
// cleanup dist directory
fs.emptyDirSync(outPath);
const browser = {
mode: isProduction ? 'production' : 'development',
context: browserSourcePath,
entry: ['./index.tsx', './main.css'],
output: {
path: path.join(outPath, 'browser'),
filename: 'bundle.js',
},
target: 'web',
resolve: {
extensions: ['.js', '.ts', '.tsx'],
mainFields: ['main'],
},
devtool: isProduction ? false : 'source-map',
module: {
rules: [
// .ts, .tsx
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
configFile: 'browser/tsconfig.json',
},
},
// scss
{
test: /\.css$/,
use: [
{
loader: 'file-loader',
options: {
name: 'bundle.css',
},
},
'extract-loader',
'css-loader?-url',
],
},
],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: 'index.ejs', to: path.join(outPath, 'browser', 'src', 'index.ejs') },
]
}),
],
};
const server = {
mode: isProduction ? 'production' : 'development',
context: serverSourcePath,
entry: ['./extension.ts'],
output: {
path: path.join(outPath, 'src'),
filename: 'extension.js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '[absoluteResourcePath]',
},
target: 'node',
node: {
__dirname: false,
},
resolve: {
extensions: ['.js', '.ts'],
},
devtool: isProduction ? false : '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/
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
},
],
},
],
},
};
module.exports = [browser, server];