Problem with accentuation in . js after Concat and uglify in Gulp

Asked

Viewed 425 times

3

I’m trying to optimize the organ site where I work and I’m facing problems after concatenating and minifying the Avascripts.

Our Apache server uses ISO-8859-1 and all my files in Phpstorm are configured in that same charset.

After doing the Concat and Uglify in Gulp (which worked correctly), I had problems with accentuation in some system functionalities, for example the "Datepicker" of jQuery-ui.

Where it should be written "Schedule" is "Hor? river".

I’ve tried using the "Gulp-Convert-encoding" and set it to ISO-8859-1, but it also didn’t work.

follows the stretch where I call the archives, concateno and minifico:

var js  = [
    './msg/js/jquery-1.10.1.min.js',
    './placeholder/jquery-placeholder.js',
    './msg/js/msg.js',
    './enviarArquivo/js/ajaxupload.3.5.js',
    './funcoes/funcoes.js',
    '../../../padroes/interface/scripts/shadowbox.js', // Padrão de interfaces
    './calendario/jquery-ui-1.10.3.custom.js',
    './calendario/jquery-ui-timepicker-addon.js',
    './combobox/chosen.jquery.js',
];

gulp.task('minify-js', function () {
    gulp.src(js)
        .pipe(concat('script.min.js'))
        .pipe(convertEncoding({to: 'ISO-8859-1'}))
        .pipe(uglify())
        .pipe(gulp.dest('../pages/template/js/dist/'))
        .pipe(notify('Javascript compilado e minificado!'));
});

I saw that when finished compiling, the file script.minjs. stands as UTF-8 and all accented characters are replaced by (?).

  • 1

    I was looking at Soen’s suggestion to use stringfinal= decodeURIComponent(escape(stringinicial));. Check it out if you can resolve: http://stackoverflow.com/a/5396742/2256325. Check it out here as well: https://www.npmjs.com/package/gulp-utf8-convert

  • Hello, @Sergio. Thank you very much, but you can’t do it this way since there are thousands of lines of code to check. Another thing: any Alert that we try to use and that has accentuation also presents problem. All files are in ISO-8859-1 and only after running Gulp the file turns UTF-8.

  • And can’t convert the entire file string to UTF? Are you opening the file on Node? or receiving string content on Node?

  • @Sergio actually tried to convert the file but the error remains. I am not opening on Node. I am viewing directly by the site, which is in PHP.

  • 1

    Man to me you already identified the problem, "All files are in ISO-8859-1". Cannot convert files to UTF-8?

  • Tried to enable the ASCIIOnly?

  • @Kaduamaral, thanks for the help. I have now tried to enable Asciionly and it also didn’t work. About converting the files into UTF8, I can’t. These files are used in various systems (actually I have no way of knowing how many) of a state public body. Any problem causes taxpayers, tax auditors and accountants, jam the phone. :(

  • I converted one of the files to UT8 to test and it really worked. I used . pipe(convertEncoding({to: 'ISO-8859-1'})) and saved min.js as ISO. I will seek to know what I can convert and try. Thank you for now.

  • 1

    @Buback Already tried to convert to UTF-8 before concatenating and to ISO after concatenating?

  • 1

    The default for any project is UTF-8, you don’t need to use ISO-8859-1 format, because of accentuation, this only forces you to have to convert characters to special formats. UTF-8 recognizes accentuation. No conversion required.

Show 5 more comments

2 answers

1

if you use convertEncoding with from and to, all work fine:

 gulp.src('tmp/js/lib/**/*.js')
     //.pipe(stripCode({}))
     .pipe(convertEncoding({from: 'ISO-8859-15', to: 'UTF-8'}))
     .pipe(uglify())
     .pipe(convertEncoding({from: 'UTF-8', to: 'ISO-8859-15'}))
     .pipe(gulp.dest('dist/js/'));
  • It’s Stackoverflow in English, you must Translate your Answer.

0


After several attempts, the only one that worked was converting each file to UTF8 before doing Concat and Minify. All accents worked correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.