Re: Updating ResourceMinimizer to handle ES6

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Updating ResourceMinimizer to handle ES6

Svein
<dependency>
    <groupId>org.apache.tapestry</groupId>
    <artifactId>tapestry-webresources</artifactId>
    <exclusions>
        <exclusion>
            <groupId>com.google.javascript</groupId>
            <artifactId>closure-compiler</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>com.google.javascript</groupId>
    <artifactId>closure-compiler</artifactId>

    <version>v20151216</version>
</dependency>


@Contribute(ResourceMinimizer.class)
@Primary
public static void overrideJavaScriptMinimizer(final MappedConfiguration<String, ResourceMinimizer> configuration) {
    configuration.overrideInstance("text/javascript", MyGoogleClosureMinimizer.class);
}




package com.jacilla.core.services;

import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.*;
import org.apache.commons.io.IOUtils;
import org.apache.tapestry5.internal.webresources.GoogleClosureMinimizer;
import org.apache.tapestry5.ioc.OperationTracker;
import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.assets.AssetChecksumGenerator;
import org.apache.tapestry5.services.assets.StreamableResource;
import org.apache.tapestry5.webresources.WebResourcesSymbols;
import org.slf4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.List;

public class MyGoogleClosureMinimizer extends GoogleClosureMinimizer {
    private final static String OUTPUT_CHARSET = "utf-8";

    private final List<SourceFile> EXTERNS = Collections.emptyList();

    private final CompilationLevel compilationLevel;

    public MyGoogleClosureMinimizer(Logger logger, OperationTracker tracker, AssetChecksumGenerator checksumGenerator, Request request, @Symbol(WebResourcesSymbols.COMPILATION_LEVEL) CompilationLevel compilationLevel) {
        super(logger, tracker, checksumGenerator, request, compilationLevel);
        this.compilationLevel = compilationLevel;
    }

    @Override
    protected InputStream doMinimize(StreamableResource resource) throws IOException {
        CompilerOptions options = new CompilerOptions();

        compilationLevel.setOptionsForCompilationLevel(options);

        options.setLanguage(CompilerOptions.LanguageMode.ECMASCRIPT6);


        options.setCodingConvention(new ClosureCodingConvention());
        options.setOutputCharset(OUTPUT_CHARSET);
        options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING);

        com.google.javascript.jscomp.Compiler compiler = new Compiler();

        compiler.disableThreads();

        SourceFile input = SourceFile.fromInputStream(resource.toString(), resource.openStream(), Charset.defaultCharset());

        List<SourceFile> inputs = Collections.singletonList(input);

        Result result = compiler.compile(EXTERNS, inputs, options);

        if (result.success) {
            return IOUtils.toInputStream(compiler.toSource(), OUTPUT_CHARSET);
        }

        throw new RuntimeException(String.format("Compilation failed: %s.",
                InternalUtils.join(CollectionFactory.newList(result.errors), ";")));
    }
}





tsconfig.json

{
  "compilerOptions": {
    "target": "es2015",




Reply | Threaded
Open this post in threaded view
|

RE: Updating ResourceMinimizer to handle ES6

Svein
The topic I tried to answer was in the [hidden email] Mailing List Archive

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Updating ResourceMinimizer to handle ES6

Svein
The topic I tried to answer was in the Dev Mailing List Archive


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Updating ResourceMinimizer to handle ES6

Erik Fäßler-2
In reply to this post by Svein
Yes, thanks a lot, I already had trouble with this. Will check it out as soon as I am back working on the respective stuff.

> On 26. Aug 2019, at 09:21, Svein-Erik Løken <[hidden email]> wrote:
>
> The topic I tried to answer was in the [hidden email] Mailing List Archive
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]