forked from Eugeny/tabby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.plugin.config.js
132 lines (126 loc) · 4.71 KB
/
webpack.plugin.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
const path = require('path')
const webpack = require('webpack')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const bundleAnalyzer = new BundleAnalyzerPlugin({
analyzerPort: 0,
})
module.exports = options => {
const sourceMapOptions = {
exclude: [/node_modules/, /vendor/],
filename: '[file].map',
moduleFilenameTemplate: `webpack-tabby-${options.name}:///[resource-path]`,
}
let SourceMapDevToolPlugin = webpack.SourceMapDevToolPlugin
if (process.env.CI) {
sourceMapOptions.append = '\n//# sourceMappingURL=../../../app.asar.unpacked/assets/webpack/[url]'
}
if (process.platform === 'win32' && process.env.TABBY_DEV) {
SourceMapDevToolPlugin = webpack.EvalSourceMapDevToolPlugin
}
const isDev = !!process.env.TABBY_DEV
const config = {
target: 'node',
entry: 'src/index.ts',
context: options.dirname,
devtool: false,
output: {
path: path.resolve(options.dirname, 'dist'),
filename: 'index.js',
pathinfo: true,
libraryTarget: 'umd',
publicPath: 'auto',
},
mode: isDev ? 'development' : 'production',
optimization:{
minimize: false,
},
cache: !isDev ? false : {
type: 'filesystem',
cacheDirectory: path.resolve(options.dirname, 'node_modules', '.webpack-cache'),
},
resolve: {
alias: options.alias ?? {},
modules: ['.', 'src', 'node_modules', '../app/node_modules', '../node_modules'].map(x => path.join(options.dirname, x)),
extensions: ['.ts', '.js'],
},
ignoreWarnings: [/Failed to parse source map/],
module: {
rules: [
...options.rules ?? [],
{
test: /\.js$/,
enforce: 'pre',
use: {
loader: 'source-map-loader',
options: {
filterSourceMappingUrl: (url, resourcePath) => {
if (/node_modules/.test(resourcePath)) {
return false
}
return true
},
},
},
},
{
test: /\.ts$/,
use: {
loader: 'ts-loader',
options: {
configFile: path.resolve(options.dirname, 'tsconfig.json'),
allowTsInNodeModules: true,
},
},
},
{ test: /\.pug$/, use: ['apply-loader', 'pug-loader'] },
{ test: /\.scss$/, use: ['@tabby-gang/to-string-loader', 'css-loader', 'sass-loader'], include: /(theme.*|component)\.scss/ },
{ test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'], exclude: /(theme.*|component)\.scss/ },
{ test: /\.css$/, use: ['@tabby-gang/to-string-loader', 'css-loader'], include: /component\.css/ },
{ test: /\.css$/, use: ['style-loader', 'css-loader'], exclude: /component\.css/ },
{ test: /\.yaml$/, use: ['json-loader', 'yaml-loader'] },
{ test: /\.svg/, use: ['svg-inline-loader'] },
{
test: /\.(ttf|eot|otf|woff|woff2|ogg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
type: 'asset',
},
],
},
externals: [
'@electron/remote',
'@serialport/bindings',
'any-promise',
'child_process',
'electron-promise-ipc',
'electron-updater',
'electron',
'fontmanager-redux',
'fs',
'keytar',
'macos-native-processlist',
'native-process-working-directory',
'net',
'ngx-toastr',
'os',
'path',
'readline',
'socksv5',
'stream',
'windows-native-registry',
'windows-process-tree',
'windows-process-tree/build/Release/windows_process_tree.node',
/^@angular/,
/^@ng-bootstrap/,
/^rxjs/,
/^tabby-/,
...options.externals || [],
],
plugins: [
new SourceMapDevToolPlugin(sourceMapOptions),
],
}
if (process.env.PLUGIN_BUNDLE_ANALYZER === options.name) {
config.plugins.push(bundleAnalyzer)
config.cache = false
}
return config
}