Npm run script with dynamically computed parameters
I currently have this script in my package.json, for building the app to work on the cdn:
"build:cdn": "ng build --prod --extract-css --output-hashing=none --deploy-url https://my-cdn.com/static/20181118000000/frontend/dist/"
Where 20181118000000
is simply the convention for cache busting.
But that means that every time I want to build, I have to manually edit that value in the build:cdn
script in package.json. Not to mention that I can't have the app running in watch mode...
How can I tell npm to dynamically compute that when running the command? Like --deploy-url https://my-cdn.com/static/{getCurrentTimeStampHereAndFormatItTo('YYYYMMDDHHMMSS')}/frontend/dist/
whatever.
Especially since I would also like to use npm run build:cdn -- --watch
to have it watching and build automatically when saving a file, while developing. Because local development also uses CDN - don't ask why :( - but it's a VM in the cloud, and with EACH change the code is automatically uploaded (thanks to WebStorm) through ftp to that development VM in the cloud, then I can refresh the browser to see the changes. Apparently, people preferred this over the Docker filesystem issues with mounted folders being slow.
Ideally, the solution should work on both Windows and Mac OS.
npm
add a comment |
I currently have this script in my package.json, for building the app to work on the cdn:
"build:cdn": "ng build --prod --extract-css --output-hashing=none --deploy-url https://my-cdn.com/static/20181118000000/frontend/dist/"
Where 20181118000000
is simply the convention for cache busting.
But that means that every time I want to build, I have to manually edit that value in the build:cdn
script in package.json. Not to mention that I can't have the app running in watch mode...
How can I tell npm to dynamically compute that when running the command? Like --deploy-url https://my-cdn.com/static/{getCurrentTimeStampHereAndFormatItTo('YYYYMMDDHHMMSS')}/frontend/dist/
whatever.
Especially since I would also like to use npm run build:cdn -- --watch
to have it watching and build automatically when saving a file, while developing. Because local development also uses CDN - don't ask why :( - but it's a VM in the cloud, and with EACH change the code is automatically uploaded (thanks to WebStorm) through ftp to that development VM in the cloud, then I can refresh the browser to see the changes. Apparently, people preferred this over the Docker filesystem issues with mounted folders being slow.
Ideally, the solution should work on both Windows and Mac OS.
npm
2
Just write a script in the language of your choice (shell or JS probably simplest) and invoke that instead.
– jonrsharpe
Nov 18 '18 at 19:48
well, unless there is a straight-forward and simple solution, I guess I'll have to see how can I do that (I have zero shell/bash scripting experience... and anyway, either bash or JS script will just add complexity to the simple use ofng build
command) maybe there is a simpler solution, I hope... I'll wait for a while before doing anything else. thanks for the suggestion @jonrsharpe !
– MrCroft
Nov 18 '18 at 19:53
You can call that from the script, I just mean to build the parameters. You still runnpm run build:cdn
and it'd still end up calling the Angular CLI.
– jonrsharpe
Nov 18 '18 at 20:12
add a comment |
I currently have this script in my package.json, for building the app to work on the cdn:
"build:cdn": "ng build --prod --extract-css --output-hashing=none --deploy-url https://my-cdn.com/static/20181118000000/frontend/dist/"
Where 20181118000000
is simply the convention for cache busting.
But that means that every time I want to build, I have to manually edit that value in the build:cdn
script in package.json. Not to mention that I can't have the app running in watch mode...
How can I tell npm to dynamically compute that when running the command? Like --deploy-url https://my-cdn.com/static/{getCurrentTimeStampHereAndFormatItTo('YYYYMMDDHHMMSS')}/frontend/dist/
whatever.
Especially since I would also like to use npm run build:cdn -- --watch
to have it watching and build automatically when saving a file, while developing. Because local development also uses CDN - don't ask why :( - but it's a VM in the cloud, and with EACH change the code is automatically uploaded (thanks to WebStorm) through ftp to that development VM in the cloud, then I can refresh the browser to see the changes. Apparently, people preferred this over the Docker filesystem issues with mounted folders being slow.
Ideally, the solution should work on both Windows and Mac OS.
npm
I currently have this script in my package.json, for building the app to work on the cdn:
"build:cdn": "ng build --prod --extract-css --output-hashing=none --deploy-url https://my-cdn.com/static/20181118000000/frontend/dist/"
Where 20181118000000
is simply the convention for cache busting.
But that means that every time I want to build, I have to manually edit that value in the build:cdn
script in package.json. Not to mention that I can't have the app running in watch mode...
How can I tell npm to dynamically compute that when running the command? Like --deploy-url https://my-cdn.com/static/{getCurrentTimeStampHereAndFormatItTo('YYYYMMDDHHMMSS')}/frontend/dist/
whatever.
Especially since I would also like to use npm run build:cdn -- --watch
to have it watching and build automatically when saving a file, while developing. Because local development also uses CDN - don't ask why :( - but it's a VM in the cloud, and with EACH change the code is automatically uploaded (thanks to WebStorm) through ftp to that development VM in the cloud, then I can refresh the browser to see the changes. Apparently, people preferred this over the Docker filesystem issues with mounted folders being slow.
Ideally, the solution should work on both Windows and Mac OS.
npm
npm
asked Nov 18 '18 at 19:42
MrCroftMrCroft
1,64912138
1,64912138
2
Just write a script in the language of your choice (shell or JS probably simplest) and invoke that instead.
– jonrsharpe
Nov 18 '18 at 19:48
well, unless there is a straight-forward and simple solution, I guess I'll have to see how can I do that (I have zero shell/bash scripting experience... and anyway, either bash or JS script will just add complexity to the simple use ofng build
command) maybe there is a simpler solution, I hope... I'll wait for a while before doing anything else. thanks for the suggestion @jonrsharpe !
– MrCroft
Nov 18 '18 at 19:53
You can call that from the script, I just mean to build the parameters. You still runnpm run build:cdn
and it'd still end up calling the Angular CLI.
– jonrsharpe
Nov 18 '18 at 20:12
add a comment |
2
Just write a script in the language of your choice (shell or JS probably simplest) and invoke that instead.
– jonrsharpe
Nov 18 '18 at 19:48
well, unless there is a straight-forward and simple solution, I guess I'll have to see how can I do that (I have zero shell/bash scripting experience... and anyway, either bash or JS script will just add complexity to the simple use ofng build
command) maybe there is a simpler solution, I hope... I'll wait for a while before doing anything else. thanks for the suggestion @jonrsharpe !
– MrCroft
Nov 18 '18 at 19:53
You can call that from the script, I just mean to build the parameters. You still runnpm run build:cdn
and it'd still end up calling the Angular CLI.
– jonrsharpe
Nov 18 '18 at 20:12
2
2
Just write a script in the language of your choice (shell or JS probably simplest) and invoke that instead.
– jonrsharpe
Nov 18 '18 at 19:48
Just write a script in the language of your choice (shell or JS probably simplest) and invoke that instead.
– jonrsharpe
Nov 18 '18 at 19:48
well, unless there is a straight-forward and simple solution, I guess I'll have to see how can I do that (I have zero shell/bash scripting experience... and anyway, either bash or JS script will just add complexity to the simple use of
ng build
command) maybe there is a simpler solution, I hope... I'll wait for a while before doing anything else. thanks for the suggestion @jonrsharpe !– MrCroft
Nov 18 '18 at 19:53
well, unless there is a straight-forward and simple solution, I guess I'll have to see how can I do that (I have zero shell/bash scripting experience... and anyway, either bash or JS script will just add complexity to the simple use of
ng build
command) maybe there is a simpler solution, I hope... I'll wait for a while before doing anything else. thanks for the suggestion @jonrsharpe !– MrCroft
Nov 18 '18 at 19:53
You can call that from the script, I just mean to build the parameters. You still run
npm run build:cdn
and it'd still end up calling the Angular CLI.– jonrsharpe
Nov 18 '18 at 20:12
You can call that from the script, I just mean to build the parameters. You still run
npm run build:cdn
and it'd still end up calling the Angular CLI.– jonrsharpe
Nov 18 '18 at 20:12
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364767%2fnpm-run-script-with-dynamically-computed-parameters%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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364767%2fnpm-run-script-with-dynamically-computed-parameters%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
Just write a script in the language of your choice (shell or JS probably simplest) and invoke that instead.
– jonrsharpe
Nov 18 '18 at 19:48
well, unless there is a straight-forward and simple solution, I guess I'll have to see how can I do that (I have zero shell/bash scripting experience... and anyway, either bash or JS script will just add complexity to the simple use of
ng build
command) maybe there is a simpler solution, I hope... I'll wait for a while before doing anything else. thanks for the suggestion @jonrsharpe !– MrCroft
Nov 18 '18 at 19:53
You can call that from the script, I just mean to build the parameters. You still run
npm run build:cdn
and it'd still end up calling the Angular CLI.– jonrsharpe
Nov 18 '18 at 20:12