Deploy minfied javascript files and debug [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
so i completed building a new angular application and i would like to deploy it into production... of course i have prepared all my angular code such that it can be minified so i am covered there!! But something i dont understand... i have very good code separation and full unit testing of my application... as a result, of course, there are a lot of script tags on my main page.
I need to of course debug my javascript during runtime as i develop, but then when i go to deploy i need to minify. What is the best practice here? Is this literally a manually process of replacing the script tags with my all.min.js file after i move the code to the production machine? Do i minify all the css and html as well?? I am using gulp for the minification...
thanks for the help....

In the absence of server side templating (like Razor or Thymeleaf) I would suggest using gulp-preprocess, gulp-processhtml, or gulp-html-replace.

Use gulp to concat your files in development as well as production. You'll probably want to use gulp-sourcemaps to be able to debug your client-side javascript as if they were separate files.
Here's a sample gulpfile.js
gulp.task('script', function(){
gulp.src('./app/**/*.js')
.pipe(sourcemaps.init())
.pipe(concat('application.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./build'))
})
gulp.task('script:prod', function(){
gulp.src('./app/**/*.js')
.pipe(concat('application.js'))
.pipe(ugilfy())
.pipe(gulp.dest('./build'))
})
Then in your view, just point it at the build file.
<script src="/build/application.js"></script>
When you deploy, run gulp script:prod. In development, run gulp script.

Related

What kind of scripts should I use for npm scripts? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I want to extend the npm run build command in my package.json not by replacing it, because it uses react-scripts build but by &&'ing another script.
Fastest way to achieve this would be a bash script which just does that. I want to copy a few other files from src into build in order to make a chrome extension out of it.
Is it considered bad practice to use a shell script here rather than writing it natively in a node environment?
Not exactly a bad practice and it is often done in practice but keep in mind that it will be less portable because it will not work on systems where the shell that you use for scripting (e.g. Bash or whatever is in the shebang line) is not available.
I recently wrote an answer to the question on how to solve a problem with installing Node modules that require Bash on Windows:
'bash' is not recognized as an internal or external command
So it is a problem that happens in practice.

Angular 2 build generates links to root of server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I`m trying to make my project runs in a test server, but when I run the ng build command and take the data from dist to there it always tries to load the js and css files from myserver.com/ and not from myserver.com/folder-of-project/
I thought it would be a problem on my code, but I created an empty project with angular-cli and did the build directly and also I got the same problem.
Am I missing something to do in the code before preparing the build?
Run ng build --env=prod this will build your project for production. ng-build it for local development. Also make sure inside your index.html the base href is as follows: <base href="/">
As mentioned in the comments, you'll need to append your project folder to your base href inside your index.html file
like so
<base href="/folder-of-project">

Automatically create grunt environment [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm a little lost as to how I should proceed, actually I don't even know where to start.
I've been working on a few wordpress sites lately, usually I create a dev environment using npm grunt.
I set up a folder and do npm init. Then I install all the grunt plugins I need such as: watch, sass, uglify etc... I then download wordpress and set up the gruntfile.js so that for example my sass will compile to my wordpress theme's stylesheet. Just the usual (I hope).
The thing is rather than always repeating the same step over and over I'd like to automate it ( same config step for each site ).
So here is my question, how do you go about creating a script that will automaticaly install grunt plugins and configure them, download the latest wordpress and set up the theme files ( domain name etc...)?
I don't need an explanation on how to do all these steps but just a few pointers on where to start and what tools to use would be great. Being quite the novice in script writing any information is good to use.
Try yeoman.
There is yeoman generator for wordperss boilerplate. It uses gulp instead grunt, but has same idea that you need.

Configuration files : JS vs INI [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I need to implement configuration files for an application im developing.
I was wondering whether it is better to use INI files or JS files(JSON data)
for the configuration files.
What are the security concerns? Could a file permission be set to the js files that a user cannot retrieve them via the browser but the php can read them?
Best way to handle that kind of configuration is to keep it outside of your public directory, so that users won't be able to access it.
Generally in web applications you have web-accessible directory. For example: web/ in Symfony 2.x and public/ in Laravel 4/5. In these folders you would usually find index.php file which user runs when accesses your website. If you move your file outside of this folder - (cd ..) - into your application root directory where you might see directories like vendor/ then here you could store files which ordinary user would not be able to download just using some link to the file.
About file extension. Actually lately it has become quite popular to name your config files in "dot" format. For example: production or .my_config which not only protects you from users accidentally downloading files (since dot files are usually not accessible), but it also lets you keep your config files out of version control software such as git, so your passwords won't end up on github.

What's the preferred workflow for deploying coffescript? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Should I store .coffee files in git and compile them server-side with some git hooks, or should I store both .coffee and .js files in SCM and just ignore coffee at the server?
Are there any disadvantages to storing compiled .js files except extra SCM space usage? I'd rather not have to install node, npm and coffee on each server.
The workflows that I've seen are for Rails and Node. My current process is based on them and looks like:
Keep .coffee files in /assets/src/coffee
Keep compiled .js files in /assets/js and reference them as /js/foo.js
Keep .js files that are external to your app (e.g. a graphing utility) in /assets/lib
Exclude /assets/js from your source control
Set up your middleware to compile coffeescript files on the fly if they aren't already compiled. connect-coffee-script was the one I liked best.
The process in Rails is pretty similar, to the best of my recollection.
Are there any disadvantages to storing compiled .js files except extra SCM space usage? I'd rather not have to install node, npm and coffee on each server.
I see no good reason to put compiled js into source -- your middleware should handle turning coffee into js. I also see no disadvantage to installing coffee on your server -- you should be doing an npm update as part of your build process and that should take care of it.
Here's the code for setting it up:
var app = express();
...
srcFolder = path.join(__dirname, 'assets', 'src', 'coffee');
publicFolder = path.join(__dirname, 'assets');
app.configure(function () {
...
app.use(require('connect-coffee-script')({
src:srcFolder, dest:path.join(publicFolder, 'js'), force:true
}));
It's also important to note that I had some issues getting this going on Windows 7; node's file watchers seem to have some issues there. So I have to have a command window with this running while developing: coffee -o ./assets/js -wc ./assets/src/coffee.

Categories

Resources