2

I have to run

sudo rm -rf var/*
sudo rm -rf pub/static/frontend/*
sudo bin/magento setup:static-content:deploy

to see any changes made in my js/scripts.js file. I am in developer mode.

  • you mean you want to see js is changed or not ? – Manthan Dave Feb 7 '17 at 11:13
  • @ManthanDave I want to see my changes made in js files in frontend quickly and not having to clear static content and deploy it again. It takes a lot of time. – rits Feb 7 '17 at 11:19
  • @Rudolph thats the standard of magento2 !!! yes you need to run this all command if you do any changes in js . – Manthan Dave Feb 7 '17 at 11:20
3

When you are in developer mode, deleting the js from your static folder should be enough to regenerate it. My advice would be, just make a command line command where you quickly remove that file.

so it regenerates. that works for CSS as well. personally i run a gulp script that watches for changes in css file and deploys it to the specific pub directories as well. This helps me a lot with css. You can do the same for js.

Maybe you like to know what i use for css so you can apply something similar for js:

// Load gulp and plug-ins
var gulp    = require('gulp'),
    jshint      = require('gulp-jshint'),
    less        = require('gulp-less'),
    concat      = require('gulp-concat'),
    uglify      = require('gulp-uglify'),
    rename      = require('gulp-rename'),
    gutil       = require('gulp-util'),
    livereload  = require('gulp-livereload'),
    sourcemaps  = require('gulp-sourcemaps');


// Generate less to CSS.
gulp.task('less', function() {
    return gulp.src(['app/design/frontend/Vendor/theme/web/css/theme.less'])
        .pipe(less())
        .pipe( sourcemaps.write() )
        .pipe( livereload() )
        .pipe(gulp.dest('pub/static/frontend/Vendor/theme/nl_NL/css'))
        .pipe(gulp.dest('pub/static/frontend/Vendor/theme/de_DE/css'))
});


// Watch Files For Changes and livereload
gulp.task('watch', function() {
    livereload.listen();
    gulp.watch('app/design/frontend/Vendor/theme/web/css/**/*.less', ['less']);
});


gulp.task('default', ['less']);
  • Great, i love gulp, war better then grunt ;-) – Kay Int Veen Feb 7 '17 at 18:46
  • @Rudolph is there any chance you could please post an answer of your solution? I'm having a rough time fighting with files and trying to understand gulp. Thanks – Chris K Feb 2 '18 at 4:40
1

You can write your code in static files,

pub/static/frontend/manento/theme/en_us/yourmodel/js/yourjs

You can change directory here and check change on the frontend , after all, work done then copy your code in the main file ( in your custom module or js) after that deploy content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.