avatarKevin Tan

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

831

Abstract

github.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*xaj7bv7b4zB0gPpW)"></div> </div> </div> </a> </div><p id="c144">I believe you can do an npm run build script before you package your jar to be deployed.</p><div id="000d"><pre>npm install uglify-js <span class="hljs-attr">--save-dev</span></pre></div><p id="e7f4">Create a package.json</p><div id="1769"><pre><span class="hljs-attr">"scripts"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> <span class="hljs-attr">"build"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"uglifyjs src/main/resources/static/js/*.js -o src/main/resources/static/js/dist/bundle.min.

Options

js"</span> <span class="hljs-punctuation">}</span></pre></div><p id="9fba">Then run the build to minify/uglify your js code that contains the business logic</p><div id="6ef9"><pre>npm run build</pre></div><p id="a1c2">Then include the final js file into your Thymeleaf html</p><div id="e2da"><pre><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">th:src</span>=<span class="hljs-string">"/js/dist/bundle.min.js"</span>></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></pre></div><p id="2826">I believe every time you write your javascript business logic, you will need to run the build first before you deploy your app, or perhaps use Gradle’s build process to automate this step before running the app locally or deploy to the cloud.</p></article></body>

Thoughts about Spring Boot + Thymeleaf + Javascript + Postgres Monolith

I have been experimenting with this development setup for a while, and one thing that we might forget is to handle the frontend Javascript code in which some business logic might be coded in there as well.

So I suppose the solution to the problem is to use a JS minifier.

I believe you can do an npm run build script before you package your jar to be deployed.

npm install uglify-js --save-dev

Create a package.json

"scripts": {
  "build": "uglifyjs src/main/resources/static/js/*.js -o src/main/resources/static/js/dist/bundle.min.js"
}

Then run the build to minify/uglify your js code that contains the business logic

npm run build

Then include the final js file into your Thymeleaf html

<script th:src="/js/dist/bundle.min.js"></script>

I believe every time you write your javascript business logic, you will need to run the build first before you deploy your app, or perhaps use Gradle’s build process to automate this step before running the app locally or deploy to the cloud.

Thymeleaf
Uglifyjs
Spring
Spring Boot
Recommended from ReadMedium