Files
tabby-web/webpack.config.js

74 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-07-25 14:38:14 +02:00
require('dotenv').config()
2021-07-25 14:00:22 +02:00
const baseConfig = require('./webpack.config.base.js')
const fs = require('fs')
2021-06-25 21:55:40 +02:00
const path = require('path')
const { AngularWebpackPlugin } = require('@ngtools/webpack')
2021-07-24 20:25:09 +02:00
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
2021-07-25 14:00:22 +02:00
const HtmlWebpackPlugin = require('html-webpack-plugin')
const htmlPluginOptions = {
hash: true,
minify: false
}
const outputPath = path.join(__dirname, 'build')
const backendURL = process.env.BACKEND_URL
2021-07-25 14:38:14 +02:00
if (process.env.DEV && !backendURL) {
backendURL = 'http://localhost:8001'
}
2021-07-25 14:00:22 +02:00
if (!backendURL) {
throw new Error('BACKEND_URL env var is required')
}
2021-07-24 20:25:09 +02:00
2021-07-24 20:38:07 +02:00
module.exports = {
2021-07-25 14:00:22 +02:00
name: 'browser',
target: 'web',
...baseConfig,
entry: {
2021-07-24 20:38:07 +02:00
index: path.resolve(__dirname, 'src/index.ts'),
terminal: path.resolve(__dirname, 'src/terminal.ts'),
2021-07-25 14:00:22 +02:00
},
plugins: [
2021-07-24 20:38:07 +02:00
...baseConfig.plugins,
new AngularWebpackPlugin({
2021-07-24 20:25:09 +02:00
tsconfig: 'tsconfig.json',
directTemplateLoading: false,
skipCodeGeneration: false,
2021-07-24 20:38:07 +02:00
}),
2021-07-25 14:00:22 +02:00
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
chunks: ['index'],
...htmlPluginOptions,
}),
new HtmlWebpackPlugin({
template: './src/terminal.html',
filename: 'terminal.html',
chunks: ['terminal'],
...htmlPluginOptions,
}),
{
apply: (compiler) => {
2021-07-25 14:38:14 +02:00
compiler.hooks.afterEmit.tap('AfterEmitPlugin', () => {
2021-07-25 14:00:22 +02:00
fs.writeFileSync(path.join(outputPath, 'config.json'), JSON.stringify({
backendURL,
}))
})
},
},
],
output: {
path: outputPath,
2021-07-24 20:38:07 +02:00
pathinfo: true,
2021-07-25 14:00:22 +02:00
publicPath: '/',
2021-07-24 20:38:07 +02:00
filename: '[name].js',
chunkFilename: '[name].bundle.js',
2021-07-25 14:00:22 +02:00
},
2021-07-24 20:38:07 +02:00
}
2021-07-24 20:25:09 +02:00
if (process.env.BUNDLE_ANALYZER) {
2021-07-25 14:00:22 +02:00
module.exports[0].plugins.push(new BundleAnalyzerPlugin())
2021-07-24 20:25:09 +02:00
}