Problems with gulp encoding on Windows

I have several source files in a Visual Studio 2013 application project that I am processing with gulp version 3.8.11. These files are Unicode (UTF-8 with signature) - Codepage 65001 text files Unicode (UTF-8 with signature) - Codepage 65001 . After processing, they look like text files encoded in Windows 1252.

For example, with the following UTF-8 encoded src/hello.html :

 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Hello</title> </head> <body> <h1>Hello, my name is Jesús López</h1> </body> </html> 

Here's what it looks like in a browser:

enter image description here

Using the following gulpfile.js :

 var gulp = require('gulp'); gulp.task('build', function () { gulp.src('src/hello.html') .pipe(gulp.dest('dist')); }); 

After executing gulp build on the command line, it looks in the browser:

enter image description here

How can I solve this encoding problem? Please, help.

+6
source share
2 answers

I had the same problem with .cshtml files, I found out that this was due to the lack of the UTF-8 specification. This can be easily added using gulp-plugin named gulp -header.

 var gulp = require('gulp'); var header = require('gulp-header'); gulp.task('build', function () { gulp.src('src/hello.html') .pipe(header('\ufeff')); .pipe(gulp.dest('dist')); }); 
+14
source

I had a similar problem, I solved it by adding

 var convertEncoding = require('gulp-convert-encoding'); gulp.task("copy:templates", function () { return gulp .src("./app/**/*.html") .pipe(convertEncoding({ from: "windows1250", to: "utf8" })) //.pipe(header('\ufeff')) .pipe(gulp.dest("./wwwroot/app")); }); gulp.task('build:ts', function () { return gulp.src("./app/**/*.ts") .pipe(sourcemaps.init()) .pipe(typescript(tsconfigBuildTs)) .pipe(sourcemaps.write()) .pipe(convertEncoding({ from: "windows1250", to: "utf8" })) .pipe(gulp.dest("./wwwroot/app/")); }); 

The most important line

 .pipe(convertEncoding({ from: "windows1250", to: "utf8" })) 

You should check your file encodings from file> advanced save. My was installed on windows1250, yours may be different.

+1
source

Source: https://habr.com/ru/post/985811/


All Articles