1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-25 19:17:39 +03:00
tabby/webpack.plugin.config.mjs

186 lines
6.3 KiB
JavaScript
Raw Permalink Normal View History

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
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
}
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
if ((process.platform === 'win32' || process.platform === 'linux') && process.env.TABBY_DEV) {
devtoolPlugin = wp.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) => {
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
},
},
},
},
{
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$/,
use: [
{
loader: '@ngtools/webpack',
2021-02-13 14:11:38 +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/ },
{ 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: ['yaml-loader'] },
2021-02-13 14:11:38 +03:00
{ 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 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)
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
}