-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.nodejs.config.js
More file actions
148 lines (131 loc) · 3.47 KB
/
Copy pathwebpack.nodejs.config.js
File metadata and controls
148 lines (131 loc) · 3.47 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require("terser-webpack-plugin");
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const fs = require('fs');
let out;
const cwd = process.cwd();
if (process.env.NODE_ENV == 'production') {
out = path.resolve(cwd, 'dist');
}
else {
out = path.resolve(cwd, 'out');
}
const isProduction = process.env.NODE_ENV == 'production';
function ensureAlias(name) {
const sanitizedName = name.replace(/@/g, '').replace(/\//g, '').replace(/-/g, '');
const sanitizedPath = path.join(__dirname, 'polyfill', sanitizedName + '.js');
const contents = `const ${sanitizedName} = __non_webpack_require__('${name}'); module.exports = ${sanitizedName};`
try {
if (fs.readFileSync(sanitizedPath).toString() !== contents)
throw new Error();
}
catch (e) {
fs.writeFileSync(sanitizedPath, contents);
}
return sanitizedPath;
}
const plugins = [
new webpack.DefinePlugin({
'process.env.SSDP_COV': false,
}),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
];
if (process.env.WEBPACK_ANALYZER) {
plugins.push(
new BundleAnalyzerPlugin({
generateStatsFile: true,
}),
);
}
const alias = {};
const polyfills = [
'node-pty-prebuilt-multiarch',
'@scrypted/node-pty',
'node-forge',
'sharp',
'source-map-support/register',
'adm-zip',
"memfs",
"realfs",
"fakefs",
"mdns",
"typescript",
];
for (const p of polyfills) {
alias[p] = ensureAlias(p);
}
module.exports = {
mode: process.env.NODE_ENV || 'development',
output: {
devtoolModuleFilenameTemplate: function (info) {
return path.relative(out, info.absoluteResourcePath);
},
// export everything to a var "window" which will be an alias for "exports" in Scrypted
library: {
name: 'exports',
type: 'assign-properties',
},
},
module: {
rules: [
// {
// test: /\.(js)x?$/,
// loader: 'babel-loader',
// },
process.env.SCRYPTED_WEBPACK_BABEL ?
{
test: /\.(ts|js)x?$/,
exclude: /(core-js)/,
use: {
loader: 'babel-loader',
options: {
"presets": [
"@babel/preset-typescript",
]
}
}
} :
{
test: /\.([cm]?ts|tsx)$/,
loader: "ts-loader",
},
{
test: /\.node$/,
loader: "node-loader",
},
],
},
node: {
__dirname: true,
},
target: "node",
resolveLoader: {
modules: module.paths,
},
resolve: {
alias,
extensions: ['.tsx', '.ts', '.js']
},
stats: {
colors: true
},
plugins,
optimization: {
minimize: isProduction,
minimizer: [
new TerserPlugin(
{
terserOptions: {
compress: {
typeofs: false,
}
}
},
),
],
},
devtool: process.env.WEBPACK_DEVTOOL || 'source-map',
};