-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
136 lines (126 loc) · 3.8 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
var webpack = require("webpack");
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var webpack_env = {};
if(!process.env.DEBUG) process.env.NODE_ENV = "production";
else process.env.NODE_ENV = "development";
// webpack_env['process.env._NODE_ENV'] = JSON.stringify(process.env.NODE_ENV);
webpack_env['global'] = "globalThis";
console.log("process.env.NODE_ENV", process.env.NODE_ENV);
var DEFINED = {
"ifdef-verbose": true, // add this for verbose output
"ifdef-triple-slash": false, // add this to use double slash comment instead of default triple slash
"ifdef-fill-with-blanks": true, // add this to remove code with blank spaces instead of "//" comments
"ifdef-uncomment-prefix": "// #code " // add this to uncomment code starting with "// #code "
};
console.log("__dirname", __dirname, process.env.DEBUG);
module.exports = function () {
var index = {
context: __dirname,
// mode: 'production',
// mode: 'development',
mode: process.env.DEBUG ? 'development' : 'production',
entry: {
requires: './requires.js'
},
devServer: {
allowedHosts: 'all',
// static: [path.resolve(__dirname, './')],
hot: false,
static:[
{
directory: path.join(__dirname, './test_app'),
publicPath: '/test_app',
},
{
directory: path.join(__dirname, './'),
publicPath: '/',
},
],
// webSocketServer: false,
client: {
progress: true,
overlay: true,
webSocketURL: {
port: 443,//needed for gitpod.io comment out if needed to run on local machine or when port needs to match
},
},
devMiddleware: {
// index: true,
// mimeTypes: { phtml: 'text/html' },
publicPath: '/browser',
// serverSideRender: true,
// writeToDisk: true,
},
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser'
}),
new webpack.DefinePlugin(webpack_env),
new HtmlWebpackPlugin({
title: 'Development',
template: './test.html',
filename: "test.html",
inject: false
}),
new CopyWebpackPlugin({
patterns: [
"./test.js",
]
})
],
node: {
global: true
},
output: {
filename: '[name].js',
library: 'requires',
path: path.resolve(__dirname, "./browser"),
clean: true,
libraryTarget: 'umd',
globalObject: 'typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : this'
},
resolve: {
fallback: {
"vm": require.resolve("vm-browserify"),
"crypto": require.resolve("crypto-browserify"),
"path": require.resolve("path-browserify"),
"stream": require.resolve("stream-browserify"),
"os": require.resolve("os-browserify"),
"https": require.resolve("https-browserify"),
"http": require.resolve("stream-http"),
"process": require.resolve("process"),
"assert": require.resolve("assert"),
"url": require.resolve("url"),
"zlib": require.resolve("browserify-zlib"),
"fs": false,
},
alias: {
process: "process/browser"
}
},
module: {
rules: [{
test: /\.(mjs|js|jsx)$/,
include: path.resolve(__dirname, "./lib"),
// exclude: /node_modules\/ifdef-loader/,
use: [{
loader: "ifdef-loader",
options: DEFINED
}],
}, {
test: /\.(mjs|js|jsx)$/,
include: /node_modules/,
type: 'javascript/auto',
resolve: {
fullySpecified: false
}
}]
},
};
console.log(index.mode);
return [index];
};