LoginSignup
3
3

More than 5 years have passed since last update.

grunt-contrib-concat 連結元のファイルパスをコメントとして挿入

Posted at

grunt-contrib-concat 連結元のファイルパスをコメントとして挿入するやり方。
https://www.npmjs.org/package/grunt-contrib-concat
に、サンプルソースとして記載されていたのですが

Gruntfile.js

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json');
        concat: {
            options: {
                process: function(src, filepath) {
                    // 連結元のファイルパスをコメントとして挿入
                    return '\n'+ '// sourceURL=' + filepath + '\n' + src;
                }
            },
            files: {
                'dist/built.js': ['src/project.js', 'src/project2.js'],
            }
    });

    // grunt.loadNpmTasks, grunt.registerTaskは省略
};

これで、grunt実行すると、

// sourceURL=src/project.js
// ここにsrc/project.jsのソース内容がはいるよ

// sourceURL=src/project2.js
// ここにsrc/project2.jsのソース内容がはいるよ

という感じで、連結前のファイルパスがコメントとして記載される。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3