2023-02-26 22:42:31 +03:00
|
|
|
import * as fs from 'fs'
|
|
|
|
import * as path from 'path'
|
|
|
|
import wp from 'webpack'
|
|
|
|
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
|
|
|
import { AngularWebpackPlugin } from '@ngtools/webpack'
|
2021-04-08 23:26:47 +03:00
|
|
|
|
|
|
|
const bundleAnalyzer = new BundleAnalyzerPlugin({
|
|
|
|
analyzerPort: 0,
|
|
|
|
})
|
2021-02-13 14:11:38 +03:00
|
|
|
|
2023-02-26 22:42:31 +03:00
|
|
|
import { createEs2015LinkerPlugin } from '@angular/compiler-cli/linker/babel'
|
|
|
|
const linkerPlugin = createEs2015LinkerPlugin({
|
|
|
|
linkerJitMode: true,
|
|
|
|
fileSystem: {
|
|
|
|
resolve: path.resolve,
|
|
|
|
exists: fs.existsSync,
|
|
|
|
dirname: path.dirname,
|
|
|
|
relative: path.relative,
|
|
|
|
readFile: fs.readFileSync,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
export default options => {
|
2021-05-16 20:41:04 +03:00
|
|
|
const sourceMapOptions = {
|
|
|
|
exclude: [/node_modules/, /vendor/],
|
|
|
|
filename: '[file].map',
|
2021-06-30 00:57:04 +03:00
|
|
|
moduleFilenameTemplate: `webpack-tabby-${options.name}:///[resource-path]`,
|
2021-05-16 20:41:04 +03:00
|
|
|
}
|
2023-02-26 22:42:31 +03:00
|
|
|
let devtoolPlugin = wp.SourceMapDevToolPlugin
|
2021-05-16 15:59:01 +03:00
|
|
|
|
2021-05-16 20:41:04 +03:00
|
|
|
if (process.env.CI) {
|
|
|
|
sourceMapOptions.append = '\n//# sourceMappingURL=../../../app.asar.unpacked/assets/webpack/[url]'
|
|
|
|
}
|
2021-05-16 15:59:01 +03:00
|
|
|
|
2023-08-11 18:57:17 +03:00
|
|
|
if ((process.platform === 'win32' || process.platform === 'linux') && process.env.TABBY_DEV) {
|
2023-02-26 22:42:31 +03:00
|
|
|
devtoolPlugin = wp.EvalSourceMapDevToolPlugin
|
2021-07-06 21:29:01 +03:00
|
|
|
}
|
|
|
|
|
2021-06-30 00:57:04 +03:00
|
|
|
const isDev = !!process.env.TABBY_DEV
|
2021-04-08 23:26:47 +03:00
|
|
|
const config = {
|
2021-02-13 14:11:38 +03:00
|
|
|
target: 'node',
|
|
|
|
entry: 'src/index.ts',
|
|
|
|
context: options.dirname,
|
2021-05-16 15:59:01 +03:00
|
|
|
devtool: false,
|
2021-02-13 14:11:38 +03:00
|
|
|
output: {
|
|
|
|
path: path.resolve(options.dirname, 'dist'),
|
|
|
|
filename: 'index.js',
|
|
|
|
pathinfo: true,
|
|
|
|
libraryTarget: 'umd',
|
2021-06-16 00:43:02 +03:00
|
|
|
publicPath: 'auto',
|
2021-02-13 14:11:38 +03:00
|
|
|
},
|
|
|
|
mode: isDev ? 'development' : 'production',
|
|
|
|
optimization:{
|
|
|
|
minimize: false,
|
|
|
|
},
|
|
|
|
cache: !isDev ? false : {
|
|
|
|
type: 'filesystem',
|
|
|
|
cacheDirectory: path.resolve(options.dirname, 'node_modules', '.webpack-cache'),
|
|
|
|
},
|
|
|
|
resolve: {
|
2021-06-25 20:42:07 +03:00
|
|
|
alias: options.alias ?? {},
|
2021-07-04 13:23:27 +03:00
|
|
|
modules: ['.', 'src', 'node_modules', '../app/node_modules', '../node_modules'].map(x => path.join(options.dirname, x)),
|
2021-02-13 14:11:38 +03:00
|
|
|
extensions: ['.ts', '.js'],
|
2022-01-08 18:02:56 +03:00
|
|
|
mainFields: ['esm2015', 'browser', 'module', 'main'],
|
2021-02-13 14:11:38 +03:00
|
|
|
},
|
2021-07-06 22:22:57 +03:00
|
|
|
ignoreWarnings: [/Failed to parse source map/],
|
2021-02-13 14:11:38 +03:00
|
|
|
module: {
|
|
|
|
rules: [
|
2021-05-24 18:48:12 +03:00
|
|
|
...options.rules ?? [],
|
2021-07-06 22:22:57 +03:00
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
enforce: 'pre',
|
2022-05-27 14:34:18 +03:00
|
|
|
use: {
|
2021-07-06 22:22:57 +03:00
|
|
|
loader: 'source-map-loader',
|
|
|
|
options: {
|
|
|
|
filterSourceMappingUrl: (url, resourcePath) => {
|
2022-11-20 22:23:31 +03:00
|
|
|
if (/node_modules/.test(resourcePath) && !resourcePath.includes('xterm')) {
|
2021-07-06 22:22:57 +03:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-02-26 22:42:31 +03:00
|
|
|
{
|
|
|
|
test: /\.(m?)js$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
plugins: [linkerPlugin],
|
|
|
|
compact: false,
|
|
|
|
cacheDirectory: true,
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
fullySpecified: false,
|
|
|
|
},
|
|
|
|
},
|
2021-02-13 14:11:38 +03:00
|
|
|
{
|
|
|
|
test: /\.ts$/,
|
2023-02-26 22:42:31 +03:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: '@ngtools/webpack',
|
2021-02-13 14:11:38 +03:00
|
|
|
},
|
2023-02-26 22:42:31 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.pug$/,
|
|
|
|
use: [
|
|
|
|
'apply-loader',
|
|
|
|
{
|
|
|
|
loader: 'pug-loader',
|
|
|
|
options: {
|
|
|
|
pretty: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2021-02-13 14:11:38 +03:00
|
|
|
},
|
2021-07-02 01:39:17 +03:00
|
|
|
{ test: /\.scss$/, use: ['@tabby-gang/to-string-loader', 'css-loader', 'sass-loader'], include: /(theme.*|component)\.scss/ },
|
2021-05-24 18:48:12 +03:00
|
|
|
{ test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'], exclude: /(theme.*|component)\.scss/ },
|
2021-07-02 01:39:17 +03:00
|
|
|
{ test: /\.css$/, use: ['@tabby-gang/to-string-loader', 'css-loader'], include: /component\.css/ },
|
2021-02-13 14:11:38 +03:00
|
|
|
{ test: /\.css$/, use: ['style-loader', 'css-loader'], exclude: /component\.css/ },
|
2023-02-26 22:42:31 +03:00
|
|
|
{ test: /\.yaml$/, use: ['yaml-loader'] },
|
2021-02-13 14:11:38 +03:00
|
|
|
{ test: /\.svg/, use: ['svg-inline-loader'] },
|
|
|
|
{
|
2022-04-02 19:06:35 +03:00
|
|
|
test: /\.(eot|otf|woff|woff2|ogg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
2021-07-31 20:28:01 +03:00
|
|
|
type: 'asset',
|
2021-02-13 14:11:38 +03:00
|
|
|
},
|
2022-04-02 19:06:35 +03:00
|
|
|
{
|
|
|
|
test: /\.ttf$/,
|
|
|
|
type: 'asset/inline',
|
|
|
|
},
|
2022-01-08 18:02:56 +03:00
|
|
|
{
|
|
|
|
test: /\.po$/,
|
|
|
|
use: [
|
|
|
|
{ loader: 'json-loader' },
|
|
|
|
{ loader: 'po-gettext-loader' },
|
|
|
|
],
|
|
|
|
},
|
2021-02-13 14:11:38 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
externals: [
|
2021-05-24 18:48:12 +03:00
|
|
|
'@electron/remote',
|
2021-07-11 23:59:39 +03:00
|
|
|
'@serialport/bindings',
|
2022-02-02 00:47:07 +03:00
|
|
|
'@serialport/bindings-cpp',
|
2021-04-08 23:26:47 +03:00
|
|
|
'any-promise',
|
2021-02-13 14:11:38 +03:00
|
|
|
'child_process',
|
|
|
|
'electron-promise-ipc',
|
2021-08-24 20:13:49 +03:00
|
|
|
'electron-updater',
|
2021-02-13 14:11:38 +03:00
|
|
|
'electron',
|
|
|
|
'fontmanager-redux',
|
|
|
|
'fs',
|
|
|
|
'keytar',
|
|
|
|
'macos-native-processlist',
|
|
|
|
'native-process-working-directory',
|
|
|
|
'net',
|
|
|
|
'ngx-toastr',
|
|
|
|
'os',
|
|
|
|
'path',
|
|
|
|
'readline',
|
2021-11-28 20:21:26 +03:00
|
|
|
'@luminati-io/socksv5',
|
2021-02-13 14:11:38 +03:00
|
|
|
'stream',
|
|
|
|
'windows-native-registry',
|
|
|
|
'windows-process-tree',
|
2021-02-13 16:10:56 +03:00
|
|
|
'windows-process-tree/build/Release/windows_process_tree.node',
|
2022-01-13 16:25:16 +03:00
|
|
|
/^@angular(?!\/common\/locales)/,
|
2021-02-13 14:11:38 +03:00
|
|
|
/^@ng-bootstrap/,
|
|
|
|
/^rxjs/,
|
2021-06-30 00:57:04 +03:00
|
|
|
/^tabby-/,
|
2021-04-08 23:26:47 +03:00
|
|
|
...options.externals || [],
|
2021-02-13 14:11:38 +03:00
|
|
|
],
|
2021-05-16 15:59:01 +03:00
|
|
|
plugins: [
|
2023-02-26 22:42:31 +03:00
|
|
|
new devtoolPlugin(sourceMapOptions),
|
|
|
|
new AngularWebpackPlugin({
|
|
|
|
tsconfig: path.resolve(options.dirname, 'tsconfig.json'),
|
|
|
|
directTemplateLoading: false,
|
|
|
|
jitMode: true,
|
|
|
|
})
|
2021-05-16 15:59:01 +03:00
|
|
|
],
|
2021-04-08 23:26:47 +03:00
|
|
|
}
|
|
|
|
if (process.env.PLUGIN_BUNDLE_ANALYZER === options.name) {
|
|
|
|
config.plugins.push(bundleAnalyzer)
|
2021-07-08 23:03:25 +03:00
|
|
|
config.cache = false
|
2021-02-13 14:11:38 +03:00
|
|
|
}
|
2021-04-08 23:26:47 +03:00
|
|
|
return config
|
2021-02-13 14:11:38 +03:00
|
|
|
}
|