2020-01-21 11:38:51 -09:00
|
|
|
import path from 'path';
|
2023-07-25 09:30:19 -08:00
|
|
|
|
|
|
|
|
import Copy from 'copy-webpack-plugin';
|
2020-01-21 11:38:51 -09:00
|
|
|
import TerserPlugin from 'terser-webpack-plugin';
|
|
|
|
|
import webpack from 'webpack';
|
2016-06-30 22:01:04 -08:00
|
|
|
|
2025-06-07 17:58:24 -08:00
|
|
|
// @ts-ignore
|
|
|
|
|
import PnpWebpackPlugin from 'pnp-webpack-plugin';
|
|
|
|
|
|
2025-06-07 18:52:16 -08:00
|
|
|
import { createRequire } from 'module';
|
|
|
|
|
|
2016-06-30 22:01:04 -08:00
|
|
|
const nodeEnv = process.env.NODE_ENV || 'development';
|
|
|
|
|
const isProd = nodeEnv === 'production';
|
|
|
|
|
|
2025-06-07 18:52:16 -08:00
|
|
|
const { resolveRequest } = require('pnpapi');
|
|
|
|
|
const pathToReact = resolveRequest('react', __filename);
|
|
|
|
|
console.log('Resolved react via pnpapi:', pathToReact);
|
|
|
|
|
|
|
|
|
|
|
2020-01-21 23:09:57 -09:00
|
|
|
const config: webpack.Configuration[] = [
|
2019-09-29 20:34:30 -08:00
|
|
|
{
|
|
|
|
|
mode: 'none',
|
|
|
|
|
name: 'hyper-app',
|
|
|
|
|
resolve: {
|
2025-06-07 17:58:24 -08:00
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
|
|
|
|
|
plugins: [PnpWebpackPlugin],
|
|
|
|
|
alias: {
|
|
|
|
|
react: require.resolve('react'),
|
2025-06-07 18:52:16 -08:00
|
|
|
//'react-dom': require.resolve('react-dom'),
|
2025-06-07 17:58:24 -08:00
|
|
|
}
|
2019-09-29 20:34:30 -08:00
|
|
|
},
|
2025-06-07 17:58:24 -08:00
|
|
|
resolveLoader: {
|
|
|
|
|
plugins: [PnpWebpackPlugin.moduleLoader(module)],
|
|
|
|
|
},
|
|
|
|
|
|
2019-12-18 07:28:28 -09:00
|
|
|
entry: './app/index.ts',
|
2019-09-29 20:34:30 -08:00
|
|
|
output: {
|
2019-09-30 21:50:22 -08:00
|
|
|
path: path.join(__dirname, 'target'),
|
2019-09-29 20:34:30 -08:00
|
|
|
filename: 'ignore_this.js'
|
|
|
|
|
},
|
|
|
|
|
module: {
|
|
|
|
|
rules: [
|
|
|
|
|
{
|
|
|
|
|
test: /\.(js|jsx|ts|tsx)$/,
|
|
|
|
|
exclude: /node_modules/,
|
|
|
|
|
loader: 'null-loader'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
plugins: [
|
2020-05-28 21:44:04 -08:00
|
|
|
new Copy({
|
|
|
|
|
patterns: [
|
|
|
|
|
{
|
|
|
|
|
from: './app/*.html',
|
|
|
|
|
globOptions: {ignore: ['**/node_modules/**']},
|
2021-03-06 08:04:39 -09:00
|
|
|
to: '[name][ext]'
|
2020-05-28 21:44:04 -08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: './app/*.json',
|
|
|
|
|
globOptions: {ignore: ['**/node_modules/**']},
|
2025-08-09 21:06:33 -08:00
|
|
|
to: '[name][ext]',
|
|
|
|
|
transform(content, absoluteFrom) {
|
|
|
|
|
if (absoluteFrom.endsWith('package.json')) {
|
|
|
|
|
const pkg = JSON.parse(content.toString());
|
|
|
|
|
pkg.name = 'hyper';
|
|
|
|
|
return JSON.stringify(pkg, null, 2);
|
|
|
|
|
}
|
|
|
|
|
return content;
|
|
|
|
|
}
|
2020-05-28 21:44:04 -08:00
|
|
|
},
|
2022-11-16 04:48:20 -09:00
|
|
|
{
|
|
|
|
|
from: './app/config/*.json',
|
|
|
|
|
globOptions: {ignore: ['**/node_modules/**']},
|
|
|
|
|
to: './config/[name][ext]'
|
|
|
|
|
},
|
2020-05-28 21:44:04 -08:00
|
|
|
{
|
|
|
|
|
from: './app/keymaps/*.json',
|
|
|
|
|
globOptions: {ignore: ['**/node_modules/**']},
|
2021-03-06 08:04:39 -09:00
|
|
|
to: './keymaps/[name][ext]'
|
2020-05-28 21:44:04 -08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: './app/static',
|
|
|
|
|
to: './static'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
})
|
2019-09-29 20:34:30 -08:00
|
|
|
],
|
|
|
|
|
target: 'electron-main'
|
|
|
|
|
},
|
|
|
|
|
|
2018-01-09 06:05:19 -09:00
|
|
|
{
|
2019-09-04 22:49:56 -08:00
|
|
|
mode: 'none',
|
2018-01-09 06:05:19 -09:00
|
|
|
name: 'hyper',
|
2025-06-07 18:52:16 -08:00
|
|
|
infrastructureLogging: {
|
|
|
|
|
level: 'verbose',
|
|
|
|
|
debug: true
|
|
|
|
|
},
|
2018-01-09 06:05:19 -09:00
|
|
|
resolve: {
|
2025-06-07 17:58:24 -08:00
|
|
|
plugins: [PnpWebpackPlugin],
|
2025-04-21 20:45:07 -08:00
|
|
|
alias: {
|
2025-06-07 18:52:16 -08:00
|
|
|
react: require.resolve('react'),
|
|
|
|
|
//'react-dom': require.resolve('react-dom')
|
2025-04-21 20:45:07 -08:00
|
|
|
},
|
2023-07-25 02:39:11 -08:00
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts']
|
2018-01-09 06:05:19 -09:00
|
|
|
},
|
2025-06-07 17:58:24 -08:00
|
|
|
resolveLoader: {
|
|
|
|
|
plugins: [PnpWebpackPlugin.moduleLoader(module)]
|
|
|
|
|
},
|
2018-01-09 06:05:19 -09:00
|
|
|
devtool: isProd ? 'hidden-source-map' : 'cheap-module-source-map',
|
2019-11-11 06:21:42 -09:00
|
|
|
entry: './lib/index.tsx',
|
2018-01-09 06:05:19 -09:00
|
|
|
output: {
|
2019-09-30 21:50:22 -08:00
|
|
|
path: path.join(__dirname, 'target', 'renderer'),
|
2018-01-09 06:05:19 -09:00
|
|
|
filename: 'bundle.js'
|
|
|
|
|
},
|
|
|
|
|
module: {
|
|
|
|
|
rules: [
|
|
|
|
|
{
|
2019-09-08 10:41:06 -08:00
|
|
|
test: /\.(js|jsx|ts|tsx)$/,
|
2018-01-09 06:05:19 -09:00
|
|
|
exclude: /node_modules/,
|
2025-06-07 18:52:16 -08:00
|
|
|
loader: require.resolve('babel-loader')
|
2018-01-09 06:05:19 -09:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.json/,
|
|
|
|
|
loader: 'json-loader'
|
|
|
|
|
},
|
|
|
|
|
// for xterm.js
|
|
|
|
|
{
|
|
|
|
|
test: /\.css$/,
|
2021-01-03 12:42:36 -09:00
|
|
|
use: ['style-loader', 'css-loader']
|
2018-01-09 06:05:19 -09:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
2025-04-24 20:37:56 -08:00
|
|
|
externals: {},
|
2018-01-09 06:05:19 -09:00
|
|
|
plugins: [
|
2021-01-03 12:42:36 -09:00
|
|
|
new webpack.IgnorePlugin({resourceRegExp: /.*\.js.map$/i}),
|
2017-09-25 05:26:04 -08:00
|
|
|
|
2018-01-09 06:05:19 -09:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
|
'process.env': {
|
|
|
|
|
NODE_ENV: JSON.stringify(nodeEnv)
|
|
|
|
|
}
|
|
|
|
|
}),
|
2020-05-28 21:44:04 -08:00
|
|
|
new Copy({
|
|
|
|
|
patterns: [
|
|
|
|
|
{
|
|
|
|
|
from: './assets',
|
|
|
|
|
to: './assets'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
})
|
2018-01-09 06:05:19 -09:00
|
|
|
],
|
2020-01-20 12:23:21 -09:00
|
|
|
optimization: {
|
2020-01-21 10:48:59 -09:00
|
|
|
minimize: isProd ? true : false,
|
2020-01-20 12:23:21 -09:00
|
|
|
minimizer: [new TerserPlugin()]
|
|
|
|
|
},
|
2019-09-04 22:49:56 -08:00
|
|
|
target: 'electron-renderer'
|
2018-01-09 06:05:19 -09:00
|
|
|
},
|
|
|
|
|
{
|
2019-09-04 22:49:56 -08:00
|
|
|
mode: 'none',
|
2018-01-09 06:05:19 -09:00
|
|
|
name: 'hyper-cli',
|
|
|
|
|
resolve: {
|
2019-12-14 02:29:48 -09:00
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json']
|
2018-01-09 06:05:19 -09:00
|
|
|
},
|
2020-01-21 23:09:57 -09:00
|
|
|
devtool: isProd ? false : 'cheap-module-source-map',
|
2019-12-14 02:29:48 -09:00
|
|
|
entry: './cli/index.ts',
|
2018-01-09 06:05:19 -09:00
|
|
|
output: {
|
|
|
|
|
path: path.join(__dirname, 'bin'),
|
|
|
|
|
filename: 'cli.js'
|
|
|
|
|
},
|
|
|
|
|
module: {
|
|
|
|
|
rules: [
|
|
|
|
|
{
|
2019-12-14 02:29:48 -09:00
|
|
|
test: /\.(js|jsx|ts|tsx)$/,
|
2018-01-09 06:05:19 -09:00
|
|
|
exclude: /node_modules/,
|
|
|
|
|
loader: 'babel-loader'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /index.js/,
|
|
|
|
|
loader: 'shebang-loader',
|
|
|
|
|
include: [/node_modules\/rc/]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
plugins: [
|
|
|
|
|
// spawn-sync is required by execa if node <= 0.10
|
2021-01-03 12:42:36 -09:00
|
|
|
new webpack.IgnorePlugin({resourceRegExp: /(.*\.js.map|spawn-sync)$/i}),
|
2018-01-09 06:05:19 -09:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
|
'process.env.NODE_ENV': JSON.stringify(nodeEnv)
|
|
|
|
|
})
|
|
|
|
|
],
|
2020-01-20 12:23:21 -09:00
|
|
|
optimization: {
|
2020-01-21 10:48:59 -09:00
|
|
|
minimize: isProd ? true : false,
|
2020-01-20 12:23:21 -09:00
|
|
|
minimizer: [new TerserPlugin()]
|
|
|
|
|
},
|
2018-01-09 06:05:19 -09:00
|
|
|
target: 'node'
|
|
|
|
|
}
|
|
|
|
|
];
|
2020-01-21 23:09:57 -09:00
|
|
|
|
|
|
|
|
export default config;
|