blutorange / closure-compiler-maven-plugin

Combine and minimize JavaScript with Closure Compiler.
http://blutorange.github.com/closure-compiler-maven-plugin
Apache License 2.0
52 stars 6 forks source link

Add “incremental” build support #51

Closed bogdanb closed 5 years ago

bogdanb commented 5 years ago

I’d really like a way to avoid minifying everything on on each build. Something like skipIfNewer which, when true, checks if an output file already exists and is newer than the input file and skips minifying that input file in particular.

This is mostly useful when skipMerge is true, but it could also make sense in the merged case, you just need to check all input files in that case.

blutorange commented 5 years ago

Sounds like a great idea. I already added support for incremental builds in Eclipse.

Are you talking about incremental builds when using the CLI or another IDE?

bogdanb commented 5 years ago

The CLI. I usually run "mvn package" a lot during development (building Jira add-ons, you need the jar to test any change).

The older minifier did nothing if it found the already-minimized file, so most test builds effectively skipped that part. I'd like to use closure instead, but it effectively doubles my build times even if the JS is not touched.

On Mon, Aug 5, 2019, 21:57 Andre Wachsmuth notifications@github.com wrote:

Sounds like a great idea. I already added support for incremental builds in Eclipse.

Are you talking about incremental builds when using the CLI or another IDE?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/blutorange/closure-compiler-maven-plugin/issues/51?email_source=notifications&email_token=AABXBKGTATPPFFGV6BJYF5DQDBZYHA5CNFSM4IJMLE72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3SX23A#issuecomment-518356332, or mute the thread https://github.com/notifications/unsubscribe-auth/AABXBKCKL37CDSBN2D3WBTLQDBZYHANCNFSM4IJMLE7Q .

blutorange commented 5 years ago

Yeah, I can understand that. I like your idea with the skipIfNewer option. Shouldn't be too hard to implement as the option to skip exists already for the Eclipse incremental build support. I'll take a look at it.

blutorange commented 5 years ago

You can test it out with the SNAPSHOT release if you'd like. I'll probably release version 2.9.0 during the weekend.

These options are the default so you should not have to set them explicitly:

    <groupId>com.github.blutorange</groupId>
    <artifactId>closure-compiler-maven-plugin</artifactId>
    <version>2.9.0-SNAPSHOT</version>
    <configuration>
        <skipMode>NEWER</skipMode>
        <force>false</force>
    </configuration>
bogdanb commented 5 years ago

I did a test right now, it works perfectly!

bogdanb commented 5 years ago

One thing that might be a good idea is to log an info message about how many files were minimized. (This is probably good in general, but especially useful for when these options are used.) As an example, here‘s how a build log looks in my case:

[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ rich-filters-plugin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 392 resources
[INFO]
[INFO] --- jira-maven-plugin:8.0.2:filter-plugin-descriptor (default-filter-plugin-descriptor) @ rich-filters-plugin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- closure-compiler-maven-plugin:2.9.0-SNAPSHOT:minify (minify-javascript) @ rich-filters-plugin ---
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:copy-resources (filter-plugin-fragments) @ rich-filters-plugin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:copy-resources (overwrite-plugin-fragments) @ rich-filters-plugin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources

It would be nice to see for the “minify-javascript” goal something like:

[INFO] Minifying 150 resources
[INFO] Skipped 149 already-minified (NEWER)
blutorange commented 5 years ago

It should already log which files were processed, but I added a summary that looks like this:

[INFO] --- closure-compiler-maven-plugin:2.9.0-SNAPSHOT:minify (default-minify) @ closure-compiler-maven-plugin-test-skipsome ---
[INFO] Starting JavaScript task:
[INFO] Skipping the merge step...
[INFO] Creating the minified file [script2.min.js].
[INFO] Uncompressed size: 62 bytes.
[INFO] Compressed size: 76 bytes minified (91 bytes gzipped).
[INFO] Creating the minified file [script5.min.js].
[INFO] Uncompressed size: 63 bytes.
[INFO] Compressed size: 76 bytes minified (91 bytes gzipped).

[INFO] Processed 5 output files
[INFO] Created 2 output files
[INFO] Skipped 3 output files (EXISTS)