简体   繁体   English

使用 gulp-sourcemaps 的文件名不正确

[英]Incorrect filename using gulp-sourcemaps

I'm using gulp-sourcemaps in my project to process my SASS and JavaScript.我在我的项目中使用 gulp-sourcemaps 来处理我的 SASS 和 JavaScript。 My gulpfile.js is correctly generating .map files, though Chrome is showing the wrong filenames in Developer Tools and Console.我的 gulpfile.js 正确生成了 .map 文件,尽管 Chrome 在开发者工具和控制台中显示了错误的文件名。 At the moment, I'm unsure where the issue is.目前,我不确定问题出在哪里。

My project tree:我的项目树:

gulpfile.js
public/
  sass/
    main.sass
    import/
      [.. more files and directories (all imported in main.sass) ..]
   js/
     main.js
     test.js
     min/
       sourcemaps/
         main.js.map
       main.js
       all.js
    css/
      main.css
      sourcemaps/
        main.css.map

My gulpfile.js我的 gulpfile.js

var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var sass = require('gulp-ruby-sass');
var plumber = require('gulp-plumber');
var prefix = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');

var options = {
    styles: {
        "source": "public/sass/main.sass",
        "destination": "public/css",
        "sourcemaps": "sourcemaps"
    },
    scripts: {
        "source": "public/js/*.js",
        "destination": "public/js/min",
        "sourcemaps": "sourcemaps"
    }
}

gulp.task('styles', function() {
return sass(options.styles.source, {sourcemap: true, style: 'compressed'})
    .pipe(plumber())
    .pipe(prefix("last 1 version", "> 1%", "ie 8", "ie 7"))
    .pipe(sourcemaps.write(options.styles.sourcemaps))
    .pipe(gulp.dest(options.styles.destination));
});

gulp.task('scripts', function() {
    return gulp.src(options.scripts.source)
        .pipe(plumber())
        .pipe(sourcemaps.init())
        .pipe(concat('all.js'))
        .pipe(gulp.dest(options.scripts.destination))
        .pipe(rename('main.js'))
        .pipe(uglify())
        .pipe(sourcemaps.write(options.scripts.sourcemaps, {includeContent: false, sourceRoot: '../../'}))
        .pipe(gulp.dest(options.scripts.destination));
});

gulp.task('default', ['styles', 'scripts'], function() {
    gulp.watch('public/sass/**', ['styles']);
    gulp.watch('public/js/**', ['scripts']);
});

The plan is:计划是:

  • 'styles' compiles public/sass/main.sass (which includes all of my SASS source), auto-prefixes the source, writes a sourcemap and outputs public/css/main.css 'styles' 编译 public/sass/main.sass(包括我所有的 SASS 源),自动为源添加前缀,编写源映射并输出 public/css/main.css

  • 'scripts' concatenates all files in the public/js directory, uglifies the source, writes a sourcemap and outputs public/js/min/main.js 'scripts' 连接 public/js 目录中的所有文件,丑化源代码,写入源映射并输出 public/js/min/main.js

After this entire process, I want to be left with public/css/main.css containing all my compiled, auto-prefixed, minified SASS source and public/js/min/main.js containing all my concatenated, minified, JavaScript source.在这整个过程之后,我想留下 public/css/main.css 包含我所有编译的、自动前缀的、缩小的 SASS 源和 public/js/min/main.js 包含我所有的连接、缩小的 JavaScript 源。

At the moment, styles in developer tools show the filename _box-sizing.scss (which is a dependency from public/sass/import/lib/neat), a file that contains no styles for the element I am inspecting.目前,开发人员工具中的样式显示文件名 _box-sizing.scss(它是来自 public/sass/import/lib/neat 的依赖项),该文件不包含我正在检查的元素的样式。 The filename should be _header.sass (from public/sass/import/layouts/common/_header.sass).文件名应该是 _header.sass(来自 public/sass/import/layouts/common/_header.sass)。

Similarly, the console shows main.js no matter the source file.同样,无论源文件如何,控制台都会显示 main.js。 I have public/js/main.js and public/js/test.js - these files should be concatenated and output to public/js/min/main.js.我有 public/js/main.js 和 public/js/test.js - 这些文件应该连接并输出到 public/js/min/main.js。 Both these files only contain a single console.log() for testing purposes and the filename displayed in Chrome is main.js for both.这两个文件都只包含一个用于测试目的的 console.log(),并且 Chrome 中显示的文件名都是 main.js。

I hope this makes sense.我希望这是有道理的。 Thank you in advance先感谢您

I've encountered the same problem without finding a solution.我遇到了同样的问题,但没有找到解决方案。 Maybe I'm wrong but it seems that gulp-Sourcemap has one or more issues to resolve.也许我错了,但 gulp-Sourcemap 似乎有一个或多个问题需要解决。

https://github.com/floridoo/gulp-sourcemaps/issues/94#issuecomment-165164311 https://github.com/floridoo/gulp-sourcemaps/issues/94#issuecomment-165164311

I made resolution after comment out the css beautify code in gulpfile.js我在注释掉 gulpfile.js 中的 css 美化代码后做出了解决方案

//.pipe(cssbeautify()) OR //.pipe(cssbeautify())

//.pipe(uglify())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM