Search code examples
firebasebitbucketobfuscationminifybitbucket-pipelines

JavaScript obfuscation and minification in bitbucket pipeline


I know my code is not worth stealing, but it is worth a "penny" every time someone is downloading it - so how can I make it smaller (must have)/less readable (nice to have) outside of doing it by my own and pushing it to deployable branch?

My current production pipeline looks like that:

pipelines:
   branches:
      master:
      - step:
         deployment: production
         caches:
         - node
         script:
         - npm install -g firebase-tools
         - firebase deploy --token=TOKEN --project PROJECT --non-interactive

What I have is:

  • Firebase hosting
  • simple website HTML + CSS + JS

The perfect solution for me would:

  • Leave the master branch unchanged
  • Perform the minification (and potentially obfuscation) of the code
  • Deploy it to firebase

Solution

  • So here's the solution I have decided to go with:

    pipelines:
      default:
        - step:
            deployment: production 
            # trigger: manual  # Uncomment to make this a manual deployment.
            caches:
              - node
    
        script: 
          - npm install uglify-es -g
          - uglifyjs ./public/scripts/NAME.js -c -m -o ./public/scripts/NAME.js 
          - uglifyjs ./public/scripts/NAME2.js -c -m -o ./public/scripts/NAME2.js 
          - pipe: atlassian/firebase-deploy:0.3.1
            variables:
              FIREBASE_TOKEN: 'TOKEN'
              PROJECT_ID: 'PROJECT' 
    

    It is still WIP, but it works as requested. The files are minified.

    The reasoning for the uglify-es - it is the version that supports the ES6 coding guidelines.