-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
65 lines (61 loc) · 2.09 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// This is the server config; the client is built by vue-cli-service and the stock webpack config is modified in vue.config.js
const child_process = require('child_process');
const fs = require('fs');
const NodemonPlugin = require('nodemon-webpack-plugin');
const pathlib = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const hashFiles = require('hash-files');
const GITHUB_URL = 'https://github.com/mrozekma/serial-bridge';
const gitDesc = child_process.execSync('git describe --all --long --abbrev=40 --dirty', { cwd: __dirname, encoding: 'utf8' });
const gitHash = child_process.execSync('git rev-parse HEAD', { cwd: __dirname, encoding: 'utf8' }).trim();
const buildVersion = gitDesc.replace(/^heads\//, '').trim();
const buildLink = `${GITHUB_URL}/commit/${gitHash}`;
const buildId = process.env.GITHUB_RUN_NUMBER;
const releaseLink = process.env.GITHUB_RUN_NUMBER ? `${GITHUB_URL}/releases/tag/build-${process.env.GITHUB_RUN_NUMBER}` : undefined;
const versionHash = (process.env.NODE_ENV === 'production') ? hashFiles.sync({ files: [ 'src/**' ] }) : undefined;
const definePlugin = new webpack.DefinePlugin({
BUILD_VERSION: JSON.stringify(buildVersion),
BUILD_LINK: JSON.stringify(buildLink),
BUILD_ID: JSON.stringify(buildId),
RELEASE_LINK: JSON.stringify(releaseLink),
BUILD_FILE_HASH: JSON.stringify(versionHash),
BUILD_DATE: JSON.stringify(new Date().toGMTString()),
HAS_LICENSES: JSON.stringify(process.env.NODE_ENV == 'production'),
});
module.exports = {
mode: process.env.NODE_ENV || 'development',
entry: {
server: './src/server/server.ts',
},
target: 'node',
output: {
path: pathlib.resolve(__dirname, 'dist', 'server'),
},
node: {
__dirname: true,
__filename: true,
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
},
plugins: [
definePlugin,
new NodemonPlugin({
script: './dist/server/server.js',
nodeArgs: [ '--inspect' ],
}),
],
externals: [
nodeExternals({ modulesFromFile: true }),
],
};