tabby/webpack.plugin.config.js

146 lines
5.2 KiB
JavaScript
Raw Normal View History

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
}
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
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'],
2022-01-08 15:02:56 +00:00
mainFields: ['esm2015', 'browser', 'module', 'main'],
2021-02-13 11:11:38 +00:00
},
2021-07-06 19:22:57 +00:00
ignoreWarnings: [/Failed to parse source map/],
2021-02-13 11:11:38 +00:00
module: {
rules: [
...options.rules ?? [],
2021-07-06 19:22:57 +00:00
{
test: /\.js$/,
enforce: 'pre',
2022-05-27 11:34:18 +00:00
use: {
2021-07-06 19:22:57 +00:00
loader: 'source-map-loader',
options: {
filterSourceMappingUrl: (url, resourcePath) => {
2022-11-20 19:23:31 +00:00
if (/node_modules/.test(resourcePath) && !resourcePath.includes('xterm')) {
2021-07-06 19:22:57 +00:00
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/ },
{ 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: /\.(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
},
{
test: /\.ttf$/,
type: 'asset/inline',
},
2022-01-08 15:02:56 +00:00
{
test: /\.po$/,
use: [
{ loader: 'json-loader' },
{ loader: 'po-gettext-loader' },
],
},
2021-02-13 11:11:38 +00:00
],
},
externals: [
'@electron/remote',
2021-07-11 20:59:39 +00:00
'@serialport/bindings',
2022-02-01 21:47:07 +00:00
'@serialport/bindings-cpp',
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',
'@luminati-io/socksv5',
2021-02-13 11:11:38 +00:00
'stream',
'windows-native-registry',
'windows-process-tree',
2021-02-13 13:10:56 +00:00
'windows-process-tree/build/Release/windows_process_tree.node',
/^@angular(?!\/common\/locales)/,
2021-02-13 11:11:38 +00:00
/^@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: [
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)
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
}