-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.serve.js
executable file
·167 lines (151 loc) · 5.07 KB
/
webpack.config.serve.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Development assets generation
*/
const common = require('./webpack.config.common.js');
const conf = common.configuration;
const path = require('path');
const fs = require('fs');
//const autoprefixer = require('autoprefixer');
const webpack = require('webpack');
const {
merge,
} = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const IP = process.env.IP || conf.HOSTNAME;
const PORT = process.env.PORT || conf.PORT;
const UIInfo = require('./package.json');
const UIVERSION = JSON.stringify(UIInfo.version);
const UIMetaInfo = require('./node_modules/@a2nt/meta-lightbox-js/package.json');
const NODE_ENV = 'development'; //conf.NODE_ENV || process.env.NODE_ENV;
const COMPRESS = NODE_ENV === 'production' ? true : false;
console.log('NODE_ENV: ' + NODE_ENV);
console.log('COMPRESS: ' + COMPRESS);
console.log('WebP images: ' + conf['webp']);
console.log('GRAPHQL_API_KEY: ' + conf['GRAPHQL_API_KEY']);
console.log('HTTPS: ' + conf['HTTPS']);
const plugins = [
new webpack.DefinePlugin({
UINAME: JSON.stringify(UIInfo.name),
UIVERSION: UIVERSION,
UIAUTHOR: JSON.stringify(UIInfo.author),
UIMetaNAME: JSON.stringify(UIMetaInfo.name),
UIMetaVersion: JSON.stringify(UIMetaInfo.version),
GRAPHQL_API_KEY: JSON.stringify(conf['GRAPHQL_API_KEY']),
SWVERSION: JSON.stringify(`sw-${new Date().getTime()}`),
BASE_HREF: JSON.stringify(
`http${conf['HTTPS'] ? 's' : ''}://${IP}:${PORT}`,
),
}),
//new webpack.HotModuleReplacementPlugin(),
new MiniCssExtractPlugin(),
];
const indexPath = path.join(__dirname, conf.APPDIR, conf.SRC, 'index.html');
if (fs.existsSync(indexPath)) {
plugins.push(
new HtmlWebpackPlugin({
publicPath: '',
template: path.join(conf.APPDIR, conf.SRC, 'index.html'),
templateParameters: {
NODE_ENV: NODE_ENV,
GRAPHQL_URL: conf['GRAPHQL_URL'],
STATIC_URL: conf['STATIC_URL']
},
}),
);
}
const config = merge(common.webpack, {
mode: 'development',
entry: {
/*hot: [
'react-hot-loader/patch',
'webpack-dev-server/?https://' + conf.HOSTNAME + ':' + conf.PORT,
'webpack/hot/only-dev-server',
],*/
},
output: {
path: path.join(__dirname),
filename: '[name].js',
// necessary for HMR to know where to load the hot update chunks
publicPath: `http${conf['HTTPS'] ? 's' : ''}://${conf['HOSTNAME']}:${
conf.PORT
}/`,
},
module: {
rules: [{
test: /\.(js|ts)x?$/,
//exclude: /node_modules/,
use: {
loader: '@sucrase/webpack-loader', //'babel-loader',
options: {
transforms: ['jsx'],
jsxPragma: "m",
jsxFragmentPragma: "m"
/*presets: [
'@babel/preset-env',
'@babel/react',
{
plugins: [
'@babel/plugin-proposal-class-properties',
"@babel/plugin-transform-react-jsx",
{
"pragma": "m",
"pragmaFrag": "'['"
}
],
},
], //Preset used for env setup
plugins: [
'@babel/plugin-transform-typescript',
'@babel/transform-react-jsx',
],
cacheDirectory: true,
cacheCompression: true,*/
},
},
},
{
test: /\.s?css$/,
use: [{
loader: 'style-loader', //MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
}, ],
},
{
test: /fontawesome([^.]+).(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
type: 'asset/resource',
},
{
test: /\.(gif|png|jpg|jpeg|ttf|otf|eot|svg|webp|woff(2)?)$/,
type: 'asset/resource',
}, ],
},
plugins: plugins,
devServer: {
allowedHosts: "all",
host: IP,
port: PORT,
historyApiFallback: false,
static: path.resolve(__dirname, conf['APPDIR'], conf['SRC']),
https: conf['HTTPS'],
hot: false,
//injectClient: conf['injectClient'],
headers: {
'Access-Control-Allow-Origin': '*',
'Referrer-Policy': 'unsafe-url',
'service-worker-allowed': '/',
},
},
});
module.exports = config;