1 | const HtmlWebpackPlugin = require("html-webpack-plugin");
|
2 | const fs = require("fs-extra");
|
3 | const path = require("path");
|
4 | const nodeExternals = require("webpack-node-externals");
|
5 | const webpack = require("webpack");
|
6 | const ts = require("typescript");
|
7 |
|
8 | module.exports = env => {
|
9 | const configPath = ts.findConfigFile(path.resolve(process.cwd(), "tests", env.packageName), ts.sys.fileExists, "tsconfig.json");
|
10 | const tsconfig = ts.parseJsonConfigFileContent(fs.readJsonSync(configPath), ts.sys, path.dirname(configPath));
|
11 | const alias = {};
|
12 | if (tsconfig.options.paths) {
|
13 | for (const key of Object.keys(tsconfig.options.paths)) {
|
14 | alias[key] = path.resolve(process.cwd(), "packages", env.packageName, tsconfig.options.paths[key][0].replace(/[\\/]src[\\/]([^\\/.]*)\.ts$/, ""));
|
15 | }
|
16 | }
|
17 |
|
18 | return {
|
19 | target: "node",
|
20 | mode: "development",
|
21 | devtool: "inline-source-map",
|
22 | externals: [
|
23 | nodeExternals()
|
24 | ],
|
25 | resolve: {
|
26 | extensions: [".ts", ".js", ".json"],
|
27 | alias
|
28 | },
|
29 | module: {
|
30 | rules: [
|
31 | {
|
32 | test: /\.ts$/,
|
33 | exclude: /node_modules/,
|
34 | loaders: [
|
35 | {
|
36 | loader: path.resolve(__dirname, "ts-transpile-loader.js"),
|
37 | options: {
|
38 | logger: this._logger
|
39 | }
|
40 | }
|
41 | ]
|
42 | }
|
43 | ]
|
44 | },
|
45 | plugins: [
|
46 | new HtmlWebpackPlugin({
|
47 | template: path.resolve(__dirname, "index.ejs"),
|
48 | BASE_HREF: "/"
|
49 | }),
|
50 | new webpack.DefinePlugin({
|
51 | "process.env": {
|
52 | NODE_ENV: JSON.stringify("test")
|
53 | }
|
54 | })
|
55 | ]
|
56 | }
|
57 | }; |
\ | No newline at end of file |