1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-18 15:41:54 +03:00
tabby/webpack.plugin.config.js

146 lines
5.2 KiB
JavaScript
Raw Normal View History

2021-02-13 14:11:38 +03:00
const path = require('path')
2021-05-16 15:59:01 +03:00
const webpack = require('webpack')
2021-04-08 23:26:47 +03:00
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const bundleAnalyzer = new BundleAnalyzerPlugin({
analyzerPort: 0,
})
2021-02-13 14:11:38 +03:00
2021-05-16 20:41:04 +03:00
module.exports = options => {
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
}
let SourceMapDevToolPlugin = webpack.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
if (process.platform === 'win32' && process.env.TABBY_DEV) {
SourceMapDevToolPlugin = webpack.EvalSourceMapDevToolPlugin
}
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: [
...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) => {
if (/node_modules/.test(resourcePath)) {
return false
}
return true
},
},
},
},
2021-02-13 14:11:38 +03:00
{
test: /\.ts$/,
use: {
2021-07-06 10:40:54 +03:00
loader: 'ts-loader',
2021-02-13 14:11:38 +03:00
options: {
2021-07-06 10:40:54 +03:00
configFile: path.resolve(options.dirname, 'tsconfig.json'),
allowTsInNodeModules: true,
2021-02-13 14:11:38 +03:00
},
},
},
{ test: /\.pug$/, use: ['apply-loader', 'pug-loader'] },
2021-07-02 01:39:17 +03:00
{ 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/ },
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/ },
{ test: /\.yaml$/, use: ['json-loader', 'yaml-loader'] },
{ test: /\.svg/, use: ['svg-inline-loader'] },
{
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
},
{
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: [
'@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',
'@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',
/^@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: [
new SourceMapDevToolPlugin(sourceMapOptions),
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)
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
}