Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filenames containing dots get cut off #54

Closed
tomcode opened this issue May 3, 2013 · 6 comments
Closed

Filenames containing dots get cut off #54

tomcode opened this issue May 3, 2013 · 6 comments

Comments

@tomcode
Copy link

tomcode commented May 3, 2013

I have set up a task to minify, add the suffix .min and write to file to the same folder:

expected result
dragin/without_dots.js.js -> dragin/without_dots.js.min.js
dragin/dragin.jquery.js -> dragin/dragin.jquery.min.js

obtained result
dragin/without_dots.js.js -> dragin/without_dots.js.min.js
dragin/dragin.jquery.js -> dragin/dragin.min.js

the .jquery part of dragin.jquery.js gets cut off

Output of

grunt uglify:dragin --verbose --debug --stack
Running "uglify:dragin" (uglify) task
Verifying property uglify.dragin exists in config...OK
Files: htdocs/assets/dragin/dragin.jquery.js -> htdocs/assets/dragin/dragin.min.js
Files: htdocs/assets/dragin/without_dots.js -> htdocs/assets/dragin/without_dots.min.js
Minifying with UglifyJS...Reading htdocs/assets/dragin/dragin.jquery.js...OK
OK
Writing htdocs/assets/dragin/dragin.min.js...OK
File "htdocs/assets/dragin/dragin.min.js" created.
Minifying with UglifyJS...Reading htdocs/assets/dragin/without_dots.js...OK
OK
Writing htdocs/assets/dragin/without_dots.min.js...OK
File "htdocs/assets/dragin/without_dots.min.js" created.

Done, without errors.

My task configuration

      // Does not work with filenames containing dots
      dragin: {
        // Grunt will search for "**/*.js" under "lib/" when the "minify" task
        // runs and build the appropriate src-dest file mappings then, so you
        // don't need to update the Gruntfile when files are added or removed.
        files: [
          {
            expand: true,     // Enable dynamic expansion.
            cwd: 'htdocs/assets/dragin/',      // Src matches are relative to this path.
            src: ['**/*.js', '!*.min.js'], // Actual pattern(s) to match.
            dest: 'htdocs/assets/dragin/',   // Destination path prefix.
            ext: '.min.js'    // Dest filepaths will have this extension.
          }
        ]
      }
@davidcl64
Copy link

+1

Is there a known workaround for this?

@existentialism
Copy link
Contributor

The ext option doesn't necessarily work as you'd expect, it replaces everything from the first '.' it finds.

Check out: gruntjs/grunt#625

To get it working how you're wanting, pass a rename function to implement whatever renaming logic you need.

@davidcl64
Copy link

Thank you for the workaround and, while I understand the discussion held in gruntjs/grunt#625 it does seem to be redefining convention.

http://en.wikipedia.org/wiki/Filename_extension

Other than behaving in an unexpected fashion (by convention anyway), what is the most common use case for uglify? If it is to minify js code, the current behavior flies in the face of DRY as anyone using grunt to minify JS could using expansion now has to implement the code to use the last dot convention. It's not that it isn't trivial, just that it shouldn't be necessary.

If it would be considered too much of a breaking change to use the more standard convention by default, perhaps an additional configuration parameter: useLastDot: true to change the behavior could be considered?

Or if someone was feeling really energetic useDot: n where n is a negative or positive number (1 == first dot, -1 == last dot, -2 == second to last dot [.min.js])

The explaination given in gruntjs/grunt#625 also seems a bit flawed in that a quick glance around at jquery plugins should a number with multiple dots in the names (i.e.: myplugin.jquery.js ==> myplugin.jquery.min.js) First dot convention is broken here as well. Or perhaps I am missing something more fundamental?

@existentialism
Copy link
Contributor

@davidcl64 I don't disagree with you one bit :)

Both @tkellen and @cowboy mention revisiting this in gruntjs/grunt#750, so I would definitely continue the conversation over there as this affects more than just the uglify plugin.

@davidcl64
Copy link

sounds like a plan! :)

@renatoargh
Copy link

this thread has helped me! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants