Skip to content

Commit 9e75c9b

Browse files
committed
[UI] Bundle with webpack 5
Signed-off-by: Miguel Álvarez <[email protected]>
1 parent 5a09f71 commit 9e75c9b

32 files changed

+9398
-8819
lines changed

bundles/org.openhab.ui/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
<artifactId>frontend-maven-plugin</artifactId>
3838

3939
<configuration>
40-
<nodeVersion>v16.14.2</nodeVersion>
41-
<npmVersion>8.6.0</npmVersion>
40+
<nodeVersion>v18.18.0</nodeVersion>
41+
<npmVersion>9.8.1</npmVersion>
4242
<workingDirectory>web</workingDirectory>
4343
</configuration>
4444

bundles/org.openhab.ui/web/build/webpack.config.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const webpack = require('webpack')
22
const CopyWebpackPlugin = require('copy-webpack-plugin')
33
const HtmlWebpackPlugin = require('html-webpack-plugin')
4-
const VueLoaderPlugin = require('vue-loader/lib/plugin')
4+
const { VueLoaderPlugin } = require('vue-loader')
55
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
6-
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
6+
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
77
const TerserPlugin = require('terser-webpack-plugin')
88
const WorkboxPlugin = require('workbox-webpack-plugin')
99
const WebpackAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
@@ -12,7 +12,7 @@ const CompressionPlugin = require('compression-webpack-plugin')
1212

1313
const path = require('path')
1414

15-
function resolvePath (dir) {
15+
function resolvePath(dir) {
1616
return path.join(__dirname, '..', dir)
1717
}
1818

@@ -30,25 +30,32 @@ module.exports = {
3030
],
3131
output: {
3232
path: resolvePath(isCordova ? 'cordova/www' : 'www'),
33-
filename: 'js/app.[hash].js',
33+
filename: 'js/app.[contenthash].js',
3434
publicPath: '/',
3535
hotUpdateChunkFilename: 'hot/hot-update.js',
3636
hotUpdateMainFilename: 'hot/hot-update.json'
3737
},
3838
resolve: {
39+
fallback: {
40+
"crypto": require.resolve("crypto-browserify"),
41+
"stream": require.resolve("stream-browserify"),
42+
"path": require.resolve("path-browserify"),
43+
},
3944
extensions: ['.mjs', '.js', '.vue', '.json'],
4045
alias: {
4146
vue$: 'vue/dist/vue.esm.js',
4247
'@': resolvePath('src')
4348
}
4449
},
45-
devtool: env === 'production' ? (buildSourceMaps) ? 'source-map' : 'none' : 'eval-source-map',
50+
devtool: env === 'production' ? (buildSourceMaps) ? 'source-map' : false : 'eval-source-map',
4651
devServer: {
4752
hot: true,
4853
// open: true,
4954
// compress: true,
50-
contentBase: '/www/',
51-
disableHostCheck: true,
55+
static: [
56+
path.resolve(__dirname, 'www'),
57+
],
58+
allowedHosts: "all",
5259
historyApiFallback: true,
5360
// watchOptions: {
5461
// poll: 1000,
@@ -63,9 +70,15 @@ module.exports = {
6370
maxEntrypointSize: 2500000
6471
},
6572
optimization: {
66-
minimizer: [new TerserPlugin({
67-
sourceMap: true
68-
})]
73+
moduleIds: env === 'production' ? undefined : 'named',
74+
minimizer: [
75+
new TerserPlugin({
76+
terserOptions: {
77+
sourceMap: true
78+
}
79+
}),
80+
new CssMinimizerPlugin(),
81+
]
6982
},
7083
module: {
7184
rules: [
@@ -153,26 +166,23 @@ module.exports = {
153166
},
154167
{
155168
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
156-
loader: 'url-loader',
157-
options: {
158-
limit: 10000,
159-
name: 'images/[name].[ext]'
169+
type: 'asset/resource',
170+
generator: {
171+
filename: 'images/[name].[ext]'
160172
}
161173
},
162174
{
163175
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac|m4a)(\?.*)?$/,
164-
loader: 'url-loader',
165-
options: {
166-
limit: 10000,
167-
name: 'media/[name].[ext]'
176+
type: 'asset/resource',
177+
generator: {
178+
filename: 'media/[name].[ext]'
168179
}
169180
},
170181
{
171182
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
172-
loader: 'url-loader',
173-
options: {
174-
limit: 10000,
175-
name: 'fonts/[name].[ext]'
183+
type: 'asset/resource',
184+
generator: {
185+
filename: 'fonts/[name].[ext]'
176186
}
177187
},
178188
{
@@ -185,6 +195,9 @@ module.exports = {
185195
]
186196
},
187197
plugins: [
198+
new webpack.ProvidePlugin({
199+
process: 'process/browser.js',
200+
}),
188201
new webpack.DefinePlugin({
189202
'process.env.NODE_ENV': JSON.stringify(env),
190203
'process.env.TARGET': JSON.stringify(target)
@@ -194,17 +207,10 @@ module.exports = {
194207
new ESLintPlugin({
195208
extensions: ['js', 'vue']
196209
}),
197-
new OptimizeCSSPlugin({
198-
cssProcessorOptions: {
199-
safe: true,
200-
map: { inline: false }
201-
}
202-
}),
203210
new webpack.optimize.ModuleConcatenationPlugin()
204211
] : [
205212
// Development only plugins
206213
new webpack.HotModuleReplacementPlugin(),
207-
new webpack.NamedModulesPlugin()
208214
]),
209215
new HtmlWebpackPlugin({
210216
filename: './index.html',
@@ -220,7 +226,7 @@ module.exports = {
220226
} : false
221227
}),
222228
new MiniCssExtractPlugin({
223-
filename: 'css/app.[hash].css'
229+
filename: 'css/app.[contenthash].css'
224230
}),
225231
new CopyWebpackPlugin([
226232
{
@@ -238,7 +244,8 @@ module.exports = {
238244
]),
239245
...(!isCordova ? [
240246
new WorkboxPlugin.InjectManifest({
241-
swSrc: resolvePath('src/service-worker.js')
247+
swSrc: resolvePath('src/service-worker.js'),
248+
maximumFileSizeToCacheInBytes: 100000000,
242249
})
243250
] : []),
244251
...(env === 'production' ? [

0 commit comments

Comments
 (0)