Disable liveReload.
[ustaxviewer.git] / src / ustaxviewer.ts
1 #!/usr/bin/env ts-node
2 // Copyright 2020 Blue Static <https://www.bluestatic.org>
3 // This program is free software licensed under the GNU General Public License,
4 // version 3.0. The full text of the license can be found in LICENSE.txt.
5 // SPDX-License-Identifier: GPL-3.0-only
6
7 const path = require('path');
8 const webpack = require('webpack');
9 const WebpackDevServer = require('webpack-dev-server');
10
11 const isTypescript = process.argv[1].endsWith('ts');
12
13 const args = process.argv.slice(2);
14 if (args.length != 1) {
15 throw new Error('Usage: ustaxviewer path/to/taxreturn');
16 }
17
18 const TAX_RETURN_PATH = path.resolve(args[0]);
19
20 const ROOT = (() => {
21 let r = path.resolve(__dirname, '..');
22 return isTypescript ? r : path.resolve(r, '..');
23 })();
24 const DISTROOT = path.resolve(__dirname);
25 const PUBLIC = path.resolve(ROOT, 'public');
26
27 const babelLoader = {
28 loader: 'babel-loader',
29 options: { presets: [ require('babel-preset-solid') ] }
30 };
31
32 const compiler = webpack({
33 entry: {
34 main: path.resolve(DISTROOT, isTypescript ? 'main.tsx' : 'main.jsx')
35 },
36
37 context: ROOT,
38
39 mode: isTypescript ? 'development' : 'production',
40
41 resolve: {
42 extensions: [ '.tsx', '.ts', '.jsx', '.js' ],
43 modules: [
44 DISTROOT,
45 'node_modules',
46 ]
47 },
48
49 module: {
50 rules: [
51 {
52 test: /\.tsx?$/,
53 include: DISTROOT,
54 use: [
55 babelLoader,
56 'ts-loader'
57 ]
58 },
59 {
60 test: /\.jsx?$/,
61 use: [ babelLoader ]
62 },
63 {
64 test: /\.css$/,
65 use: [
66 'style-loader',
67 {
68 loader: 'css-loader',
69 options: {
70 localsConvention: 'camelCaseOnly',
71 modules: {
72 localIdentName: '[path][name]_[local]_[hash:base64:2]'
73 }
74 }
75 }
76 ]
77 }
78 ]
79 },
80
81 output: {
82 filename: '[name].bundle.js',
83 chunkFilename: '[name].bundle.js',
84 },
85
86 optimization: {
87 minimize: false,
88 splitChunks: {
89 chunks: 'all',
90 }
91 },
92
93 performance: {
94 hints: isTypescript ? 'warning' : false
95 },
96
97 devServer: {
98 contentBase: [
99 PUBLIC,
100 path.dirname(require.resolve('@hpcc-js/wasm')),
101 ],
102 liveReload: false,
103 port: 8488
104 },
105
106 devtool: 'cheap-module-eval-source-map',
107
108 plugins: [
109 new (require('html-webpack-plugin'))({
110 inject: true,
111 template: path.resolve(PUBLIC, 'index.html')
112 }),
113 new webpack.DefinePlugin({
114 TAX_RETURN_PATH: JSON.stringify(TAX_RETURN_PATH),
115 }),
116 ]
117 });
118
119 const server = new WebpackDevServer(compiler, compiler.options.devServer);
120
121 server.listen(8488, 'localhost', () => {
122 console.log(`ustaxviewer for ${TAX_RETURN_PATH} at http://localhost:8488`);
123 });