文档 / 构建工具

(扩展)plugin

lighting自带插件体系。

命令介绍

通过以下方式可以查看light插件命令的可选选项。

C:\Users\Administrator>my_first_app>light plugin -h
Usage: plugin [command]
Lighting相关插件的搜索/更新/安装/移除
Options:
-h, --help output usage information
-a --add <name> 安装插件

两种插件的启用方式: 都会读取project.json中的plugins配置,并以此为基准(配置在project.json文件中)

  1. light release -e es6 启用的插件为plugins配置+es6
  2. light release -e 启用的插件为plugins配置

lighting-plugin-es6

<!DOCTYPE html>
<html>
<head>
<snippet id="header" />
<!-- build:css css/style.css -->
<link rel="stylesheet" href="css/style.css" />
<!-- endbuild -->
<title>demo</title>
</head>
<body>
<div id="main">
<view id="demo" home="true" />
</div>
<snippet id="footer" />
</body>
<script type="text/javascript" src="//res.lightyy.com/lighting/framework/light-1.0.min.js"></script>
<!-- build:js js/app.js -->
<script src="test.js"></script>
<!-- inject:view -->
<!-- endinject -->
<!-- endbuild -->
<script type="text/javascript">
App.start();
</script>
</html>

src/test.es6

var a = [];
for (let i = 0; i < 10; i++) {
a[i] = function () {
console.log(i);
};
}
a[6](); // 6

project.json

{
"project":"demo",
"version":"0.0.1",
"desc":"Just For Fun",
"type":"light-1.0",
"plugins":["es6"]
}

打包编译时可以使用指令: light release -e(project.json配置有plugins的情况下) 或者 light release -e es6

lighting-plugin-jade

doctype html
html
body
h1 My Site
p Welcome to my super lame site.
<!DOCTYPE html>
<html>
<body>
<h1>My Site</h1>
<p>Welcome to my super lame site.</p>
</body>
</html>

project.json

{
"project":"demo",
"version":"0.0.1",
"desc":"Just For Fun",
"type":"light-1.0",
"plugins":["jade"]
}

打包编译时可以使用指令: light release -e(project.json配置有plugins的情况下) 或者 light release -e jade

lighting-plugin-cachemanifest

{
"project":"demo",
"version":"0.0.1",
"desc":"Just For Fun",
"type":"light-1.0",
"plugins":["cachemanifest"]
}

打包编译时可以使用指令: light release -e(project.json配置有plugins的情况下) 或者 light release -e cachemanifest

lighting-plugin-template

<%_.each([2,3,4],function(i){%>
<%=i%>
<%})%>

project.json

{
"project":"demo",
"version":"0.0.1",
"desc":"Just For Fun",
"type":"light-1.0",
"plugins":["template"]
}

打包编译时可以使用指令: light release -e(project.json配置有plugins的情况下) 或者 light release -e template

lighting-plugin-less

.content{
color:red;
.row{
color:green;
}
}

src/html/index.html

<!DOCTYPE html>
<html>
<head>
<snippet id="header" />
<!-- build:css css/style.css -->
<link rel="stylesheet" href="css/index.css" />
<!-- endbuild -->
<title>demo</title>
</head>
<body>
<div id="main">
<view id="demo" home="true" />
</div>
<snippet id="footer" />
</body>
<script type="text/javascript" src="//res.lightyy.com/lighting/framework/light-1.0.min.js"></script>
<!-- build:js js/app.js -->
<!-- inject:view -->
<!-- endinject -->
<!-- endbuild -->
<script type="text/javascript">
App.start();
</script>
</html>

project.json

{
"project":"demo",
"version":"0.0.1",
"desc":"Just For Fun",
"type":"light-1.0",
"plugins":["less"]
}

打包编译时可以使用指令: light release -e(project.json配置有plugins的情况下) 或者 light release -e less

lighting-plugin-vue

<template>
<div id="app">
<hello></hello>
</div>
<div>
<group>
<cell title="vue" value="cool"></cell>
</group>
</div>
</template>
<script>
import Hello from './lib/Hello.vue'
import { Style, Group, Cell } from '../plugins/vux.js'
export default {
components: {
Hello,
Style, // style component is necessary
Group,
Cell
}
}
</script>
<style>
a{
display:none;
}
</style>

src/vue/lib/Hello.vue

<template>
<div class="hello">
<h1>{{ msg }}</h1>
</div>
</template>
<script>
export default {
data () {
return {
// Note: modifying `msg` below will not cause changes to occur with
// hot-reload. As reloaded components preserve their initial state,
// modifying these values will have no effect.
msg: 'Hello World123!'
}
}
}
</script>

src/html/index.html

<!DOCTYPE html>
<html>
<head>
<snippet id="header" />
<!-- build:css css/style.css -->
<link rel="stylesheet" href="css/style.css" />
<!-- endbuild -->
<title>demo</title>
</head>
<body>
<div id="main">
<view id="demo" home="true" />
</div>
<snippet id="footer" />
</body>
<script type="text/javascript" src="//res.lightyy.com/lighting/framework/light-1.0.min.js"></script>
<!-- build:js js/app.js -->
<script src="vue-components.js"></script>
<!-- inject:view -->
<!-- endinject -->
<!-- endbuild -->
<script type="text/javascript">
App.start();
</script>
</html>

src/html/view/demo.html

<div id="demo" style="display:none;">
<vue-app></vue-app>
</div>

project.json

{
"project":"demo",
"version":"0.0.1",
"desc":"Just For Fun",
"type":"light-1.0",
"plugins":["vue"]
}

打包编译时可以使用指令: light release -e(project.json配置有plugins的情况下) 或者 light release -e vue

lighting-plugin-imagemin

light release -e imagemin

压缩之前

压缩之前225K

压缩之后

压缩之后34.4K