How can I minify Javascript code in Gitlab CI?












0















I write Javascript code for the web which I usually minify before uploading.
I do it locally with a dedicated tool (like UglifyJS) but I would like to automate the process slightly using Gitlab Continuous Integration (because I use Gitlab on this project).



My aim seems quite simple: use Gitlab CI to minify the code on certain events and output these files in a convenient way for me to get them.



However, I haven't found anything (tutorial or other) to do this yet.



I have very little experience with Gitlab CI so I don't really know where to start but I have tried breaking that into smaller problems:
- I can't find a simple script that does compression/minification that I could run using Gitlab CI, it's mostly bigger utilities (YUI Compressor, Google Closure Compiler).
- If I find a way to compress the files can I push them on my repository from the CI? And if yes, I am wondering if that's actually good practice because that would version the minified files which is not useful.



My best shot at something not too complicated seems to be Google Closure Compiler which can be used with its API. And if I understand correctly, I could use Gitlab's Webhooks to make that API call (not sure exactly how I would pass the data this way but I'll see what I can do). But then, how can I read the response (Gitlab Webhooks don't seem fit for that) ?
Maybe it would be better to make these API calls in Gitlab CI directly but I am not sure how to be honest and mostly how I can get the compressed data back and what I could do with it (where to store it).










share|improve this question


















  • 1





    Why don't you build or search for a Docker image that minifies your Javascript? If you can do it locally, you should be able to replicate it on a Gitlab CI job.

    – djuarez
    Nov 15 '18 at 16:25






  • 2





    Maybe this gist is a starting point: gist.github.com/Apokly/c25fdf7e42c35d6a080a14dc3919da45 it seems to me that its almost what you need.

    – Claudio Acciaresi
    Nov 15 '18 at 18:43











  • Indeed, this looks like what I want to do! I will look into it! I have never worked with Docker images before but I will also try to see if I can do something this way thanks.

    – DylanM
    Nov 16 '18 at 9:30
















0















I write Javascript code for the web which I usually minify before uploading.
I do it locally with a dedicated tool (like UglifyJS) but I would like to automate the process slightly using Gitlab Continuous Integration (because I use Gitlab on this project).



My aim seems quite simple: use Gitlab CI to minify the code on certain events and output these files in a convenient way for me to get them.



However, I haven't found anything (tutorial or other) to do this yet.



I have very little experience with Gitlab CI so I don't really know where to start but I have tried breaking that into smaller problems:
- I can't find a simple script that does compression/minification that I could run using Gitlab CI, it's mostly bigger utilities (YUI Compressor, Google Closure Compiler).
- If I find a way to compress the files can I push them on my repository from the CI? And if yes, I am wondering if that's actually good practice because that would version the minified files which is not useful.



My best shot at something not too complicated seems to be Google Closure Compiler which can be used with its API. And if I understand correctly, I could use Gitlab's Webhooks to make that API call (not sure exactly how I would pass the data this way but I'll see what I can do). But then, how can I read the response (Gitlab Webhooks don't seem fit for that) ?
Maybe it would be better to make these API calls in Gitlab CI directly but I am not sure how to be honest and mostly how I can get the compressed data back and what I could do with it (where to store it).










share|improve this question


















  • 1





    Why don't you build or search for a Docker image that minifies your Javascript? If you can do it locally, you should be able to replicate it on a Gitlab CI job.

    – djuarez
    Nov 15 '18 at 16:25






  • 2





    Maybe this gist is a starting point: gist.github.com/Apokly/c25fdf7e42c35d6a080a14dc3919da45 it seems to me that its almost what you need.

    – Claudio Acciaresi
    Nov 15 '18 at 18:43











  • Indeed, this looks like what I want to do! I will look into it! I have never worked with Docker images before but I will also try to see if I can do something this way thanks.

    – DylanM
    Nov 16 '18 at 9:30














0












0








0








I write Javascript code for the web which I usually minify before uploading.
I do it locally with a dedicated tool (like UglifyJS) but I would like to automate the process slightly using Gitlab Continuous Integration (because I use Gitlab on this project).



My aim seems quite simple: use Gitlab CI to minify the code on certain events and output these files in a convenient way for me to get them.



However, I haven't found anything (tutorial or other) to do this yet.



I have very little experience with Gitlab CI so I don't really know where to start but I have tried breaking that into smaller problems:
- I can't find a simple script that does compression/minification that I could run using Gitlab CI, it's mostly bigger utilities (YUI Compressor, Google Closure Compiler).
- If I find a way to compress the files can I push them on my repository from the CI? And if yes, I am wondering if that's actually good practice because that would version the minified files which is not useful.



My best shot at something not too complicated seems to be Google Closure Compiler which can be used with its API. And if I understand correctly, I could use Gitlab's Webhooks to make that API call (not sure exactly how I would pass the data this way but I'll see what I can do). But then, how can I read the response (Gitlab Webhooks don't seem fit for that) ?
Maybe it would be better to make these API calls in Gitlab CI directly but I am not sure how to be honest and mostly how I can get the compressed data back and what I could do with it (where to store it).










share|improve this question














I write Javascript code for the web which I usually minify before uploading.
I do it locally with a dedicated tool (like UglifyJS) but I would like to automate the process slightly using Gitlab Continuous Integration (because I use Gitlab on this project).



My aim seems quite simple: use Gitlab CI to minify the code on certain events and output these files in a convenient way for me to get them.



However, I haven't found anything (tutorial or other) to do this yet.



I have very little experience with Gitlab CI so I don't really know where to start but I have tried breaking that into smaller problems:
- I can't find a simple script that does compression/minification that I could run using Gitlab CI, it's mostly bigger utilities (YUI Compressor, Google Closure Compiler).
- If I find a way to compress the files can I push them on my repository from the CI? And if yes, I am wondering if that's actually good practice because that would version the minified files which is not useful.



My best shot at something not too complicated seems to be Google Closure Compiler which can be used with its API. And if I understand correctly, I could use Gitlab's Webhooks to make that API call (not sure exactly how I would pass the data this way but I'll see what I can do). But then, how can I read the response (Gitlab Webhooks don't seem fit for that) ?
Maybe it would be better to make these API calls in Gitlab CI directly but I am not sure how to be honest and mostly how I can get the compressed data back and what I could do with it (where to store it).







javascript gitlab webhooks minify gitlab-ci






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 10:21









DylanMDylanM

171210




171210








  • 1





    Why don't you build or search for a Docker image that minifies your Javascript? If you can do it locally, you should be able to replicate it on a Gitlab CI job.

    – djuarez
    Nov 15 '18 at 16:25






  • 2





    Maybe this gist is a starting point: gist.github.com/Apokly/c25fdf7e42c35d6a080a14dc3919da45 it seems to me that its almost what you need.

    – Claudio Acciaresi
    Nov 15 '18 at 18:43











  • Indeed, this looks like what I want to do! I will look into it! I have never worked with Docker images before but I will also try to see if I can do something this way thanks.

    – DylanM
    Nov 16 '18 at 9:30














  • 1





    Why don't you build or search for a Docker image that minifies your Javascript? If you can do it locally, you should be able to replicate it on a Gitlab CI job.

    – djuarez
    Nov 15 '18 at 16:25






  • 2





    Maybe this gist is a starting point: gist.github.com/Apokly/c25fdf7e42c35d6a080a14dc3919da45 it seems to me that its almost what you need.

    – Claudio Acciaresi
    Nov 15 '18 at 18:43











  • Indeed, this looks like what I want to do! I will look into it! I have never worked with Docker images before but I will also try to see if I can do something this way thanks.

    – DylanM
    Nov 16 '18 at 9:30








1




1





Why don't you build or search for a Docker image that minifies your Javascript? If you can do it locally, you should be able to replicate it on a Gitlab CI job.

– djuarez
Nov 15 '18 at 16:25





Why don't you build or search for a Docker image that minifies your Javascript? If you can do it locally, you should be able to replicate it on a Gitlab CI job.

– djuarez
Nov 15 '18 at 16:25




2




2





Maybe this gist is a starting point: gist.github.com/Apokly/c25fdf7e42c35d6a080a14dc3919da45 it seems to me that its almost what you need.

– Claudio Acciaresi
Nov 15 '18 at 18:43





Maybe this gist is a starting point: gist.github.com/Apokly/c25fdf7e42c35d6a080a14dc3919da45 it seems to me that its almost what you need.

– Claudio Acciaresi
Nov 15 '18 at 18:43













Indeed, this looks like what I want to do! I will look into it! I have never worked with Docker images before but I will also try to see if I can do something this way thanks.

– DylanM
Nov 16 '18 at 9:30





Indeed, this looks like what I want to do! I will look into it! I have never worked with Docker images before but I will also try to see if I can do something this way thanks.

– DylanM
Nov 16 '18 at 9:30












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317229%2fhow-can-i-minify-javascript-code-in-gitlab-ci%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317229%2fhow-can-i-minify-javascript-code-in-gitlab-ci%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python