comparison 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
comparison
equal deleted inserted replaced
28:c751380b70c5 29:45ed53428e74
1 const glob = require('glob');
2 const jest = require('jest');
1 const path = require("path"); 3 const path = require("path");
2 const webpack = require('webpack');
3 const PnpWebpackPlugin = require('pnp-webpack-plugin'); 4 const PnpWebpackPlugin = require('pnp-webpack-plugin');
4 5
5 module.exports = { 6 const base = {
6 entry: ['./src/streamed-graph.ts'], 7 devtool: 'source-map',
7 output: {
8 filename: 'streamed-graph.bundle.js',
9 path: path.resolve(__dirname, 'build'),
10 publicPath: '/build/'
11 },
12 module: { 8 module: {
13 rules: [ 9 rules: [
14 { 10 {
15 test: /\.ts$/, 11 test: /\.ts$/,
16 loader: require.resolve('ts-loader'), 12 loader: require.resolve('ts-loader'),
17 options: PnpWebpackPlugin.tsLoaderOptions({ 13 options: PnpWebpackPlugin.tsLoaderOptions({})
18 // ... regular options go there ...
19 })
20 }, 14 },
21 { test: /\.css$/i, use: ['file-loader'] }, 15 {
16 test: /\.css$/i,
17 use: ['file-loader']
18 },
22 ] 19 ]
23 }, 20 },
24 devtool: 'source-map',
25 resolve: { 21 resolve: {
26 extensions: [".ts", ".js"], 22 extensions: [".ts", ".js"],
27 plugins: [ 23 plugins: [PnpWebpackPlugin],
28 PnpWebpackPlugin,
29 ],
30 },
31 resolveLoader: {
32 plugins: [
33 PnpWebpackPlugin.moduleLoader(module),
34 ],
35 },
36 watchOptions: {
37 ignored: /node_modules/,
38 poll: 200
39 },
40 devServer: {
41 port: 8082,
42 publicPath: '/build/',
43 contentBase: __dirname
44 } 24 }
45 }; 25 };
26
27 function outputToBundle(bundleName) {
28 return {
29 filename: bundleName,
30 path: path.resolve(__dirname, 'build'),
31 publicPath: '/build/'
32 };
33 }
34
35 module.exports = [
36 Object.assign({
37 name: "main",
38 entry: ['./src/streamed-graph.ts'],
39 output: outputToBundle('streamed-graph.bundle.js'),
40 devServer: {
41 port: 8082,
42 publicPath: '/build/',
43 contentBase: __dirname
44 }
45 }, base),
46 Object.assign({
47 name: "test",
48 entry: glob.sync('src/**/*.test.ts').map((p) => './' + p),
49 output: outputToBundle('test.bundle.js'),
50 plugins: [
51 {
52 apply: (compiler) => {
53 compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => {
54 jest.run([
55 '--detectOpenHandles', // not just to debug; having this quiets a jest error.
56 '--testRegex', 'test.bundle.js', 'build/test.bundle.js']);
57 });
58 }
59 }
60 ]
61 }, base)
62 ];