-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
114 lines (109 loc) · 3.58 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
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
const path = require('path')
const webpack = require('webpack')
const nodeExternals = require('webpack-node-externals')
var WebpackObfuscator = require('webpack-obfuscator');
const externalsFunc = nodeExternals();
//const IgnoreDynamicRequire = require('webpack-ignore-dynamic-require');
class IgnoreDynamicRequire {
apply (compiler) {
compiler.hooks.normalModuleFactory.tap('IgnoreDynamicRequire', factory => {
factory.hooks.parser.for('javascript/auto').tap('IgnoreDynamicRequire', (parser, options) => {
parser.hooks.call.for('require').tap('IgnoreDynamicRequire', expression => {
// This is a SyncBailHook, so returning anything stops the parser, and nothing allows to continue
if (expression.arguments.length !== 1 || expression.arguments[0].type === 'Literal') {
return
}
const arg = parser.evaluateExpression(expression.arguments[0])
if (!arg.isString() && !arg.isConditional()) {
/*if (arg.prefix && arg.prefix.string == "./platform_") {
//console.log(`arg.isString(): ${arg.isString()}, arg.isConditional(): ${arg.isConditional()}, expression.arguments[0]: ${JSON.stringify(expression.arguments[0],null,2)}, arg: ${JSON.stringify(arg,null,2)}`);
console.log(`disable IgnoreDynamicRequire for "./platform_*.js" require`);
return;
}*/
return true;
}
});
});
});
}
}
//const HtmlWebPackPlugin = require("html-webpack-plugin")
module.exports = {
mode: 'production',
entry: {
"multithreadserver-public": './src/multithreadserver-public.js',
restserver: './src/restserver.js',
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: '[name].js'
},
target: 'node',
/*node: {
// Need this when working with express, otherwise the build fails
__dirname: false, // if you don't put this is, __dirname
__filename: false, // and __filename return blank or /
},*/
externals: [
nodeExternals(),
], // Need this to avoid error when working with Express
optimization: {
splitChunks: {
chunks: 'all',
},
},
module: {
rules: [
{
// Transpiles ES6-8 into ES5
test: /\.js$/,
exclude: [
/node_modules/,
path.resolve(__dirname, 'common.js'),
path.resolve(__dirname, "node_modules")
],
/*use: {
loader: "babel-loader"
}*/
enforce: 'post',
use: {
loader: WebpackObfuscator.loader,
options: {
rotateStringArray: true
}
}
},
{ test: /\.pl$/, loader: 'ignore-loader' },
{ test: /\.xml$/, loader: 'ignore-loader' },
{ test: /\.txt$/, loader: 'ignore-loader' },
{ test: /\.sh$/, loader: 'ignore-loader' },
{ test: /\.md$/, loader: 'ignore-loader' },
{ test: /\.pegjs$/, loader: 'ignore-loader' },
{ test: /LICENSE$/, loader: 'ignore-loader' },
{ test: /\.jar$/, loader: 'ignore-loader' },
//
/*{
// Loads the javacript into html template provided.
// Entry point is set below in HtmlWebPackPlugin in Plugins
test: /\.html$/,
use: [{loader: "html-loader"}]
}*/
]
},
plugins: [
new IgnoreDynamicRequire()
],
/*plugins: [
new WebpackObfuscator ({
rotateStringArray: true
}, ['excluded_bundle_name.js'])
]*/
/*plugins: [
new HtmlWebPackPlugin({
template: "./index.html",
filename: "./index.html",
excludeChunks: [ 'server' ]
})
]*/
}