diff --git a/bundles/org.openhab.ui/CONTRIBUTING.md b/bundles/org.openhab.ui/CONTRIBUTING.md index d6d9f1e9d..91849d39f 100644 --- a/bundles/org.openhab.ui/CONTRIBUTING.md +++ b/bundles/org.openhab.ui/CONTRIBUTING.md @@ -16,7 +16,8 @@ Change to the `web` directory, gather the necessary dependencies with `npm insta ## NPM Scripts * `npm start` - run the development server (see below) -* `npm run build-prod` - build web app for production (note: no need to prepare a production version when submitting a PR, the build server will do it) +* `npm run build:prod` - build web app for production (note: no need to prepare a production version when submitting a PR, the build server will do it) +* `npm run build:mvn` - build web app through Maven for production (note: no need to prepare a production version when submitting a PR, the build server will do it) * `npm run dev` - run the development server (same as above) * `npm run dev:blockly` - run the development server with Blockly source-maps (allows Blockly debugging) * `npm run test:unit` - start the Jest test runner and run the unit tests diff --git a/bundles/org.openhab.ui/pom.xml b/bundles/org.openhab.ui/pom.xml index ce13438dc..16fd4c178 100644 --- a/bundles/org.openhab.ui/pom.xml +++ b/bundles/org.openhab.ui/pom.xml @@ -32,6 +32,19 @@ + + + org.apache.maven.plugins + maven-clean-plugin + + + + web/node_modules + + + + + com.github.eirslett frontend-maven-plugin @@ -42,52 +55,36 @@ web + + Install node and npm install-node-and-npm - generate-resources + prepare-package - npm ci + npm install npm + prepare-package - ci + install --save false - npm run build-prod + npm run build:mvn npm + prepare-package - run build-prod ${project.version} - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - - add-resource - - generate-resources - - - - web/www - app - - + run build:mvn ${project.version} diff --git a/bundles/org.openhab.ui/web/build/build.js b/bundles/org.openhab.ui/web/build/build.js index 662ac0795..6944f78cb 100644 --- a/bundles/org.openhab.ui/web/build/build.js +++ b/bundles/org.openhab.ui/web/build/build.js @@ -10,12 +10,14 @@ const config = require('./webpack.config.js'); const env = process.env.NODE_ENV || 'development'; const target = process.env.TARGET || 'web'; +const maven = process.env.MAVEN || false; +const outPath = maven ? '../target/classes/app' : 'www'; const spinner = ora(env === 'production' ? chalk.cyan('Building for production...') : chalk.cyan('Building development version...')); spinner.start(); exec(`npm run generate-build-info ${process.argv[2]}`).then(() => { - return rm('./www/') + return rm(outPath) }).then(() => { webpack(config, (err, stats) => { if (err) throw err; diff --git a/bundles/org.openhab.ui/web/build/webpack.config.js b/bundles/org.openhab.ui/web/build/webpack.config.js index 99646abb9..e08ef61f4 100644 --- a/bundles/org.openhab.ui/web/build/webpack.config.js +++ b/bundles/org.openhab.ui/web/build/webpack.config.js @@ -19,6 +19,8 @@ function resolvePath(dir) { const env = process.env.NODE_ENV || 'development' const target = process.env.TARGET || 'web' const buildSourceMaps = process.env.SOURCE_MAPS || false +const maven = process.env.MAVEN || false +const outPath = maven ? '../target/classes/app' : 'www' const apiBaseUrl = process.env.OH_APIBASE || 'http://localhost:8080' @@ -31,7 +33,7 @@ module.exports = { './src/js/app.js' ], output: { - path: resolvePath('www'), + path: resolvePath(outPath), filename: 'js/app.[contenthash].js', publicPath: '/', hotUpdateChunkFilename: 'hot/[id].[fullhash].hot-update.js', @@ -263,15 +265,15 @@ module.exports = { patterns: [ { from: resolvePath('src/res'), - to: resolvePath('www/res') + to: resolvePath(`${outPath}/res`) }, { from: resolvePath('src/manifest.json'), - to: resolvePath('www/manifest.json') + to: resolvePath(`${outPath}/manifest.json`) }, { from: resolvePath('src/robots.txt'), - to: resolvePath('www/robots.txt') + to: resolvePath(`${outPath}/robots.txt`) } ] }), diff --git a/bundles/org.openhab.ui/web/package.json b/bundles/org.openhab.ui/web/package.json index 2fd9bf953..f2e3a881a 100644 --- a/bundles/org.openhab.ui/web/package.json +++ b/bundles/org.openhab.ui/web/package.json @@ -24,7 +24,8 @@ }, "scripts": { "generate-build-info": "node build/generate-build-info.mjs", - "build-prod": "cross-env NODE_ENV=production node ./build/build.js", + "build:prod": "cross-env NODE_ENV=production node ./build/build.js", + "build:mvn": "cross-env NODE_ENV=production cross-env MAVEN=true node ./build/build.js", "webpack-analyzer": "cross-env NODE_ENV=production cross-env WEBPACK_ANALYZER=1 node ./build/build.js", "webpack-analyzer-report": "cross-env NODE_ENV=production cross-env WEBPACK_ANALYZER=1 WEBPACK_ANALYZER_REPORT=1 node ./build/build.js", "webpack-analyzer-report-stats": "cross-env NODE_ENV=production cross-env WEBPACK_ANALYZER=1 WEBPACK_ANALYZER_REPORT=1 WEBPACK_ANALYZER_REPORT_STATS=1 node ./build/build.js",