.js files inside public folder are modified on build process



  • Quasar v1.14.1
    Quasar app 2.1.1

    I have .js file inside public directory. After build process (quasar build) I get modified version of file.

    It is a problem for me, because this file shoud remain as JSON string, but compiler collapses spaces and makes other unexpected modifications to file. It becomes JS Object, but not JSON string after that.

    So, why is that? As I understand no modifications to files should be made inside public directory. I need this file to be ported AS IS.

    How can I fix it?

    export default {
      "readme": "sadasf",
    
      "version": {
        "major": 0,
        "minor": 45,
        "patch": 20
      }
    };
    

    it becomes

    export default{readme:"sadasf",version:{major:0,minor:45,patch:20}};
    

    without quotes (") and so on…



  • @Taras Then try making it a true JSON object. Currently, you have it hosted as a JS file with export default. That’s a js object.
    You can import JSON without making it a js object.



  • @Hawkeye64 , thank you for reply. But I use this file in two different ways. I import it in my project usign import function and I download it from server using axios during runtime and parse it as JSON string… Doing so I can understand if I use last version during runtime or from browser cache and i should force to reload page…
    How should I force webpack not to modify .js files in public folder, but at the same time import it during compilation



  • It’s declared that no changes to files will be done inside public. Why do I get result that described?



  • @Taras I think what hawkeye is saying, is that you should make the file an actual JSON file, as in named public/version.json with contents:

    {
      "readme": "sadasf",
    
      "version": {
        "major": 0,
        "minor": 45,
        "patch": 20
      }
    }
    

    You should still be able to require this file. Webpack is likely changing it because it’s a JS file, and you require it in your project.



  • @beets Thank you for clarification. I required plain json file and it worked for me. My issue solved.
    @Hawkeye64 Thank you for your reply again. Now I understand what you really meant


Log in to reply