首页 技术 正文
技术 2022年11月19日
0 收藏 996 点赞 4,159 浏览 3088 个字

1. Css

We’ll use LESS CSS, all less sources are defined in the app/assets, and they will be

compiled to standard css by the build process.

Below are steps to use the less css.

a.   add sbt-less plugin to your project’s plugins.sbt

addSbtPlugin(“com.typesafe.sbt” % “sbt-less” % “1.0.0”)

b.   enable the sbt-web plugin for your project

Note: sbt-web is auto enabled in play 2.3.x, we do not need this step if our app is

based on play2.3.x

lazy val root = (project in file(“.”)).enablePlugins(SbtWeb)

c.  tell less compiler to compile related less sources

add the following lines to build.sbt of your project.

includeFilter in (Assets, LessKeys.less) := “*.less”

excludeFilter in (Assets, LessKeys.less) := “_*.less”

d.  enable compress

add the following line to build.sbt of your project.

LessKeys.compress in Assets := true

for step c & d, we can also configure these settings in Build.Scala, which is

equal to  built.sbt

e.   create less file in your assets/css(e.g.   assets/css/demo.less), you can import other

less file.

e.g.  @import “lib/bootstrap/less/bootstrap.less”;

f.    use the less in your page, just add the stylesheet reference to demo.css

e.g. <link rel=”stylesheet” type=”text/css”  href=”css/demo.css”/>

h.   LESS sources are compiled automatically during an assets command, or when

you  refresh any page in your browser while you are running in development mode.

i.     More online resource

AssetsLess

sbt-less plugin

Javascript

We’ll use RequireJS(a JavaScript file and module loader) to modularize our

JavaScript.  Using RequireJS makes it is possible to resolve and load javascript modules

on the client side while allowing server side optimization. For server side optimization

module dependencies may be minified and combined, and we can use sbt-rjs to do the

optimization.

Using RequireJS, we should write our js in modular. Below is an example on how to use

requirejs.

//demouser/UserController.js

define([], function(){

function UserController($scope, $http){

$scope.user = {“email”:””, “name”:””, “id”:null};

$scope.load = function(){

$http.get(‘user/list’)

.success(function(resp){

$scope.users = resp;

})

};

$scope.load();

}

UserController.$inject = [‘$scope’, ‘$http’];

return UserController;

});

//userMain.js,  module loader

requirejs.config({

paths: {

‘angular’: [‘../lib/angularjs/angular’],

‘angular-route’: [‘../lib/angularjs/angular-route’],

},

shim: {

‘angular’: {

exports : ‘angular’

},

‘angular-route’: {

deps: [‘angular’],

exports : ‘angular’

}

}

});

require([‘angular’, ‘./demouser/UserController’],

function(angular, UserController) {

var app = angular.module(‘app’, []);

app.controller(“UserController”, UserController);

angular.bootstrap(document, [‘app’]);

});

//page

<html>

<body>

…………………………..

<script data-main=’userMain.js’ src=”lib/requirejs/require.js”></script>

</body>

</html>

Server Side optimization

  1. add sbt-rjs plugin to your plugins.sbt of your project

addSbtPlugin(“com.typesafe.sbt” % “sbt-rjs” % “1.0.7”)

2. configure sbt-rjs  in Build.scala

includeFilter in rjs := GlobFilter(“*.js”),

RjsKeys.paths := Map(

    ”angular” -> (“../lib/angularjs/angular”, “../lib/angularjs/angular”)

),

RjsKeys.modules := Seq(

//WebJs.JS.Object(“name” -> “angularDemoMain”),//do optimization for module

   WebJs.JS.Object(“name” -> “userMain”)

)

3.  add the plugin to the asset pipeline

pipelineStages := Seq(rjs)

4. generate the minified & combined js
              The RequireJS optimizer shouldn’t generally kick-in until it is time to perform a  
              deployment. i.e. by running start, state, dist tasks.

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,893