diff webpack.config.js @ 29:45ed53428e74

fix configs to run tests (all in one bundle though)
author drewp@bigasterisk.com
date Sun, 15 Dec 2019 21:18:42 -0800
parents 86270a59ae7b
children e54941d93356
line wrap: on
line diff
--- a/webpack.config.js	Sun Dec 15 12:38:11 2019 -0800
+++ b/webpack.config.js	Sun Dec 15 21:18:42 2019 -0800
@@ -1,45 +1,62 @@
+const glob = require('glob');
+const jest = require('jest');
 const path = require("path");
-const webpack = require('webpack');
 const PnpWebpackPlugin = require('pnp-webpack-plugin');
 
-module.exports = {
-    entry: ['./src/streamed-graph.ts'],
-    output: {
-        filename: 'streamed-graph.bundle.js',
-        path: path.resolve(__dirname, 'build'),
-        publicPath: '/build/'
-    },
+const base = {
+    devtool: 'source-map',
     module: {
         rules: [
             {
                 test: /\.ts$/,
                 loader: require.resolve('ts-loader'),
-                options: PnpWebpackPlugin.tsLoaderOptions({
-                    // ... regular options go there ...
-                })
+                options: PnpWebpackPlugin.tsLoaderOptions({})
             },
-            { test: /\.css$/i, use: ['file-loader'] },
+            {
+                test: /\.css$/i,
+                use: ['file-loader']
+            },
         ]
     },
-    devtool: 'source-map',
     resolve: {
         extensions: [".ts", ".js"],
-        plugins: [
-            PnpWebpackPlugin,
-        ],
-    },
-    resolveLoader: {
-        plugins: [
-            PnpWebpackPlugin.moduleLoader(module),
-        ],
-    },
-    watchOptions: {
-        ignored: /node_modules/,
-        poll: 200
-    },
-    devServer: {
-        port: 8082,
-        publicPath: '/build/',
-        contentBase: __dirname
+        plugins: [PnpWebpackPlugin],
     }
 };
+
+function outputToBundle(bundleName) {
+    return {
+        filename: bundleName,
+        path: path.resolve(__dirname, 'build'),
+        publicPath: '/build/'
+    };
+}
+
+module.exports = [
+    Object.assign({
+        name: "main",
+        entry: ['./src/streamed-graph.ts'],
+        output: outputToBundle('streamed-graph.bundle.js'),
+        devServer: {
+            port: 8082,
+            publicPath: '/build/',
+            contentBase: __dirname
+        }
+    }, base),
+    Object.assign({
+        name: "test",
+        entry: glob.sync('src/**/*.test.ts').map((p) => './' + p),
+        output: outputToBundle('test.bundle.js'),
+        plugins: [
+            {
+                apply: (compiler) => {
+                    compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => {
+                        jest.run([
+                            '--detectOpenHandles', // not just to debug; having this quiets a jest error.
+                            '--testRegex', 'test.bundle.js', 'build/test.bundle.js']);
+                    });
+                }
+            }
+        ]
+    }, base)
+];