Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ buildscript {
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.15.1"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:3.0.11"
classpath 'com.bertramlabs.plugins:sass-asset-pipeline:3.0.11'
}
}

Expand Down Expand Up @@ -51,7 +52,8 @@ dependencies {
runtime "org.glassfish.web:el-impl:2.1.2-b03"
runtime "com.h2database:h2"
runtime "org.apache.tomcat:tomcat-jdbc"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.15.1"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:3.0.11"
assets 'com.bertramlabs.plugins:sass-asset-pipeline:3.0.11'
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.grails.plugins:geb"
testCompile "org.grails:grails-web-testing-support"
Expand Down
12 changes: 12 additions & 0 deletions grails-app/assets/javascripts/application.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This is a manifest file that'll be compiled into application.js.
//
// Any JavaScript file within this directory can be referenced here using a relative path.
//
// You're free to add application-wide JavaScript to this file, but it's generally better
// to create separate JavaScript files as needed.
//
//= require jquery-3.3.1.min
import './bootstrap'
//= require popper.min
//= require_self

2 changes: 1 addition & 1 deletion grails-app/views/layouts/main.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<g:message code="spinner.alt" default="Loading&hellip;"/>
</div>

<asset:javascript src="application.js"/>
<asset:javascript src="application.es6"/>

</body>
</html>
39 changes: 39 additions & 0 deletions src/main/groovy/demo/asset/es6/Es6AssetFile.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package demo.asset.es6

import asset.pipeline.AbstractAssetFile
import asset.pipeline.processors.JsNodeInjectProcessor
import asset.pipeline.processors.JsProcessor
import asset.pipeline.processors.JsRequireProcessor
import groovy.transform.CompileStatic

import java.util.regex.Pattern

/**
* An {@link asset.pipeline.AssetFile} implementation for ES6 Javascript
*
* @author Roman Chychyna
*/
@CompileStatic
class Es6AssetFile extends AbstractAssetFile {
static final List<String> contentType = ['application/javascript', 'application/x-javascript', 'text/javascript']
static List<String> extensions = ['es6', 'es7', 'es8', 'es']
static String compiledExtension = 'js'
static processors = [JsProcessor, JsNodeInjectProcessor, FastBabelJsProcessor, JsRequireProcessor]
Pattern directivePattern = ~/(?m)^\/\/=(.*)/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package demo.asset.es6

class FastBabelJsProcessedContainer {

String value

String input

FastBabelJsProcessedContainer(String value, String input) {
this.value = value
this.input = input
}
}
24 changes: 24 additions & 0 deletions src/main/groovy/demo/asset/es6/FastBabelJsProcessor.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package demo.asset.es6

import asset.pipeline.AssetCompiler
import asset.pipeline.AssetFile
import asset.pipeline.processors.BabelJsProcessor
import groovy.util.logging.Commons

@Commons
class FastBabelJsProcessor extends BabelJsProcessor {
FastBabelJsProcessor(AssetCompiler precompiler) {
super(precompiler)
}

@Override
String process(String input, AssetFile assetFile) {
def start = System.currentTimeMillis()
def cache = FastBabelJsProcessorCache.getInstance()
if (!cache.has(assetFile.path) || cache.isChanged(assetFile.path, input)) {
cache.set(assetFile.path, input, super.process(input, assetFile))
}
log.debug("Duration: " + (System.currentTimeMillis() - start) + "\tFile: " + assetFile.name + "")
return cache.get(assetFile.path)
}
}
40 changes: 40 additions & 0 deletions src/main/groovy/demo/asset/es6/FastBabelJsProcessorCache.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package demo.asset.es6

class FastBabelJsProcessorCache {

private Map<String, FastBabelJsProcessedContainer> cache

static FastBabelJsProcessorCache instance

static FastBabelJsProcessorCache getInstance() {
if (!instance) {
instance = new FastBabelJsProcessorCache()
}

return instance
}

boolean has(String key) {
return getCache().containsKey(key)
}

boolean isChanged(String key, String input) {
getCache().get(key)?.input != input
}

void set(String key, String input, String value) {
getCache().put(key, new FastBabelJsProcessedContainer(value, input))
}

String get(String key) {
getCache().get(key).value
}

private Map<String, FastBabelJsProcessedContainer> getCache() {
if (!cache) {
cache = new HashMap<String, FastBabelJsProcessedContainer>()
}

cache
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/asset-pipeline/asset.specs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
demo.asset.es6.Es6AssetFile