Dynamic mapping and sharing with Grunt Uglify

I am trying to use dynamic mapping AND javascript concatenated files using Grunt Uglify.

I have the following which does not work correctly.

Here is my folder structure:

javascript
    |- account
        |- custom.js
    |- bills
        |- billing-one.js
        |- billing-two.js
    |- test (output folder)

Here is what I expect:

javascript
    |- account
        |- custom.js
    |- bills
        |- billing-one.js
        |- billing-two.js
    |- test
        |- billing-one.min.js (this file includes billing-one.js AND custom.js)
        |- billing-two.min.js (this file includes billing-two.js AND custom.js)

This is what I am getting now:

javascript
    |- account
        |- custom.js
    |- bills
        |- billing-one.js
        |- billing-two.js
    |- test
        |- bills
            |- billing-one.min.js (this file includes just billing-one.js)
            |- billing-two.min.js (this file includes just billing-two.js)
        |- account 
            |- custom.min.js (this file includes just custom.js)

It does not include the custom.js file, but instead creates 2 folders test/account/custom.min.js 'test / bills / billing-one.js' - see above

options: {
    beautify: true,
    mangle: false,
    compress: false,
    preserveComments: 'all'
},
files: [
  {
    expand: true,     // Enable dynamic expansion.
    cwd: 'javascript/',      // Src matches are relative to this path.
    src: [[bills/*.js'], 'account/custom.js'], // Actual pattern(s) to match.
    dest: 'test/',   // Destination path prefix.
    ext: '.min.js',   // Dest filepaths will have this extension.
    extDot: 'first'   // Extensions in filenames begin after the first dot
  },
],

I want all Javascript files in the folder to bills/contain custom.js

So, if there are 2 files: bills/billing-one.js bills/billing-two.js

I would expect test / folder to include

test/billing-one.min.js(this file will contain billing-one + custom.js) test/billing-two.min.js(this file will contain billing-one + custom.js)

. bills/ , concat test/.

.

:

, , - GRUNT.

, . , ... . [], cwd src.

files: [{
    expand: true,
    cwd: 'javascript/bills/',
    src: ['*.js'],
    dest: 'test/',
    ext: '.min.js',
    extDot: 'first'
}],
+1
1

grunt-contrib-uglify . https://github.com/gruntjs/grunt-contrib-uglify#banner

grunt:

grunt.initConfig({
    uglify: {
      options: {
        banner: grunt.file.read('./javascript/account/custom.js'),
        beautify: true,
        mangle: false,
        compress: false,
        preserveComments: 'all'
      },
      files: {
        expand: true,
        cwd: 'javascript/',
        src: ['bills/*.js'],
        dest: 'test/',
        ext: '.min.js',
        extDot: 'first'
      },
    }
  });

custom.js, .

, .

+1

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


All Articles