hyper/webpack.config.ts

195 lines
5 KiB
TypeScript
Raw Normal View History

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
const nodeEnv = process.env.NODE_ENV || 'development';
const isProd = nodeEnv === 'production';
2020-01-21 23:09:57 -09:00
const config: webpack.Configuration[] = [
{
mode: 'none',
name: 'hyper-app',
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json']
},
entry: './app/index.ts',
output: {
path: path.join(__dirname, 'target'),
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/**']},
to: '[name][ext]'
2020-05-28 21:44:04 -08:00
},
{
from: './app/*.json',
globOptions: {ignore: ['**/node_modules/**']},
to: '[name][ext]'
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]'
},
2021-01-07 02:43:34 -09:00
{
from: './app/yarn.lock',
to: 'yarn.lock'
},
2020-05-28 21:44:04 -08:00
{
from: './app/keymaps/*.json',
globOptions: {ignore: ['**/node_modules/**']},
to: './keymaps/[name][ext]'
2020-05-28 21:44:04 -08:00
},
{
from: './app/static',
to: './static'
}
]
})
],
target: 'electron-main'
},
{
2019-09-04 22:49:56 -08:00
mode: 'none',
name: 'hyper',
resolve: {
alias: {
react: path.resolve(__dirname, 'node_modules/react'),
'react-dom': path.resolve(__dirname, 'node_modules/react-dom')
},
2023-07-25 02:39:11 -08:00
extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts']
},
devtool: isProd ? 'hidden-source-map' : 'cheap-module-source-map',
entry: './lib/index.tsx',
output: {
path: path.join(__dirname, 'target', 'renderer'),
filename: 'bundle.js'
},
module: {
rules: [
{
2019-09-08 10:41:06 -08:00
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.json/,
loader: 'json-loader'
},
// for xterm.js
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
2022-04-14 08:50:54 -08:00
externals: {
'color-convert': 'commonjs color-convert',
'color-string': 'commonjs color-string',
columnify: 'commonjs columnify',
lodash: 'commonjs lodash',
ms: 'commonjs ms',
'normalize-url': 'commonjs normalize-url',
'parse-url': 'commonjs parse-url',
'php-escape-shell': 'commonjs php-escape-shell',
plist: 'commonjs plist',
// 'react-dom': 'commonjs react-dom',
'redux-thunk': 'commonjs redux-thunk',
redux: 'commonjs redux',
reselect: 'commonjs reselect',
'seamless-immutable': 'commonjs seamless-immutable',
stylis: 'commonjs stylis',
'@xterm/addon-unicode11': 'commonjs @xterm/addon-unicode11',
args: 'commonjs args',
mousetrap: 'commonjs mousetrap',
open: 'commonjs open',
'@xterm/addon-fit': 'commonjs @xterm/addon-fit',
'@xterm/addon-image': 'commonjs @xterm/addon-image',
'@xterm/addon-search': 'commonjs @xterm/addon-search',
'@xterm/addon-web-links': 'commonjs @xterm/addon-web-links',
'@xterm/addon-webgl': 'commonjs @xterm/addon-webgl',
'@xterm/addon-canvas': 'commonjs @xterm/addon-canvas',
xterm: 'commonjs xterm'
2022-04-14 08:50:54 -08:00
},
plugins: [
new webpack.IgnorePlugin({resourceRegExp: /.*\.js.map$/i}),
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'
}
]
})
],
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'
},
{
2019-09-04 22:49:56 -08:00
mode: 'none',
name: 'hyper-cli',
resolve: {
2019-12-14 02:29:48 -09:00
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json']
},
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',
output: {
path: path.join(__dirname, 'bin'),
filename: 'cli.js'
},
module: {
rules: [
{
2019-12-14 02:29:48 -09:00
test: /\.(js|jsx|ts|tsx)$/,
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
new webpack.IgnorePlugin({resourceRegExp: /(.*\.js.map|spawn-sync)$/i}),
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()]
},
target: 'node'
}
];
2020-01-21 23:09:57 -09:00
export default config;