2021-02-13 11:11:38 +00:00
|
|
|
const path = require('path')
|
2021-05-16 12:59:01 +00:00
|
|
|
const webpack = require('webpack')
|
2021-04-08 20:26:47 +00:00
|
|
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
|
|
|
|
|
|
|
|
const bundleAnalyzer = new BundleAnalyzerPlugin({
|
|
|
|
analyzerPort: 0,
|
|
|
|
})
|
2021-02-13 11:11:38 +00:00
|
|
|
|
2021-05-16 17:41:04 +00:00
|
|
|
module.exports = options => {
|
|
|
|
const sourceMapOptions = {
|
|
|
|
exclude: [/node_modules/, /vendor/],
|
|
|
|
filename: '[file].map',
|
2021-06-29 21:57:04 +00:00
|
|
|
moduleFilenameTemplate: `webpack-tabby-${options.name}:///[resource-path]`,
|
2021-05-16 17:41:04 +00:00
|
|
|
}
|
2021-07-06 18:29:01 +00:00
|
|
|
let SourceMapDevToolPlugin = webpack.SourceMapDevToolPlugin
|
2021-05-16 12:59:01 +00:00
|
|
|
|
2021-05-16 17:41:04 +00:00
|
|
|
if (process.env.CI) {
|
|
|
|
sourceMapOptions.append = '\n//# sourceMappingURL=../../../app.asar.unpacked/assets/webpack/[url]'
|
|
|
|
}
|
2021-05-16 12:59:01 +00:00
|
|
|
|
2021-07-06 18:29:01 +00:00
|
|
|
if (process.platform === 'win32' && process.env.TABBY_DEV) {
|
|
|
|
SourceMapDevToolPlugin = webpack.EvalSourceMapDevToolPlugin
|
|
|
|
}
|
|
|
|
|
2021-06-29 21:57:04 +00:00
|
|
|
const isDev = !!process.env.TABBY_DEV
|
2021-04-08 20:26:47 +00:00
|
|
|
const config = {
|
2021-02-13 11:11:38 +00:00
|
|
|
target: 'node',
|
|
|
|
entry: 'src/index.ts',
|
|
|
|
context: options.dirname,
|
2021-05-16 12:59:01 +00:00
|
|
|
devtool: false,
|
2021-02-13 11:11:38 +00:00
|
|
|
output: {
|
|
|
|
path: path.resolve(options.dirname, 'dist'),
|
|
|
|
filename: 'index.js',
|
|
|
|
pathinfo: true,
|
|
|
|
libraryTarget: 'umd',
|
2021-06-15 21:43:02 +00:00
|
|
|
publicPath: 'auto',
|
2021-02-13 11:11:38 +00: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 17:42:07 +00:00
|
|
|
alias: options.alias ?? {},
|
2021-07-04 10:23:27 +00:00
|
|
|
modules: ['.', 'src', 'node_modules', '../app/node_modules', '../node_modules'].map(x => path.join(options.dirname, x)),
|
2021-02-13 11:11:38 +00:00
|
|
|
extensions: ['.ts', '.js'],
|
|
|
|
},
|
2021-07-06 19:22:57 +00:00
|
|
|
ignoreWarnings: [/Failed to parse source map/],
|
2021-02-13 11:11:38 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
2021-05-24 15:48:12 +00:00
|
|
|
...options.rules ?? [],
|
2021-07-06 19:22:57 +00:00
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
enforce: 'pre',
|
|
|
|
use: {
|
|
|
|
loader: 'source-map-loader',
|
|
|
|
options: {
|
|
|
|
filterSourceMappingUrl: (url, resourcePath) => {
|
|
|
|
if (/node_modules/.test(resourcePath)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-13 11:11:38 +00:00
|
|
|
{
|
|
|
|
test: /\.ts$/,
|
|
|
|
use: {
|
2021-07-06 07:40:54 +00:00
|
|
|
loader: 'ts-loader',
|
2021-02-13 11:11:38 +00:00
|
|
|
options: {
|
2021-07-06 07:40:54 +00:00
|
|
|
configFile: path.resolve(options.dirname, 'tsconfig.json'),
|
|
|
|
allowTsInNodeModules: true,
|
2021-02-13 11:11:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ test: /\.pug$/, use: ['apply-loader', 'pug-loader'] },
|
2021-07-01 22:39:17 +00:00
|
|
|
{ test: /\.scss$/, use: ['@tabby-gang/to-string-loader', 'css-loader', 'sass-loader'], include: /(theme.*|component)\.scss/ },
|
2021-05-24 15:48:12 +00:00
|
|
|
{ test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'], exclude: /(theme.*|component)\.scss/ },
|
2021-07-01 22:39:17 +00:00
|
|
|
{ test: /\.css$/, use: ['@tabby-gang/to-string-loader', 'css-loader'], include: /component\.css/ },
|
2021-02-13 11:11:38 +00:00
|
|
|
{ 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])?$/,
|
2021-07-31 17:28:01 +00:00
|
|
|
type: 'asset',
|
2021-02-13 11:11:38 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
externals: [
|
2021-05-24 15:48:12 +00:00
|
|
|
'@electron/remote',
|
2021-07-11 20:59:39 +00:00
|
|
|
'@serialport/bindings',
|
2021-04-08 20:26:47 +00:00
|
|
|
'any-promise',
|
2021-02-13 11:11:38 +00:00
|
|
|
'child_process',
|
|
|
|
'electron-promise-ipc',
|
2021-08-24 17:13:49 +00:00
|
|
|
'electron-updater',
|
2021-02-13 11:11:38 +00:00
|
|
|
'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',
|
2021-02-13 13:10:56 +00:00
|
|
|
'windows-process-tree/build/Release/windows_process_tree.node',
|
2021-02-13 11:11:38 +00:00
|
|
|
/^@angular/,
|
|
|
|
/^@ng-bootstrap/,
|
|
|
|
/^rxjs/,
|
2021-06-29 21:57:04 +00:00
|
|
|
/^tabby-/,
|
2021-04-08 20:26:47 +00:00
|
|
|
...options.externals || [],
|
2021-02-13 11:11:38 +00:00
|
|
|
],
|
2021-05-16 12:59:01 +00:00
|
|
|
plugins: [
|
2021-07-06 18:29:01 +00:00
|
|
|
new SourceMapDevToolPlugin(sourceMapOptions),
|
2021-05-16 12:59:01 +00:00
|
|
|
],
|
2021-04-08 20:26:47 +00:00
|
|
|
}
|
|
|
|
if (process.env.PLUGIN_BUNDLE_ANALYZER === options.name) {
|
|
|
|
config.plugins.push(bundleAnalyzer)
|
2021-07-08 20:03:25 +00:00
|
|
|
config.cache = false
|
2021-02-13 11:11:38 +00:00
|
|
|
}
|
2021-04-08 20:26:47 +00:00
|
|
|
return config
|
2021-02-13 11:11:38 +00:00
|
|
|
}
|