Permalink
Browse files

Update build scripts;

压缩合并CSS/JS代码
  • Loading branch information...
1 parent f2f2723 commit 42d28b90b6568ea19728ab4482e2742cfd739cb8 @newghost committed Nov 12, 2015
Showing with 50 additions and 35 deletions.
  1. +9 −16 build.web.sh
  2. +3 −3 svr/ourjs.js
  3. +11 −8 tools/combiner.js
  4. +15 −0 web/css/prod.min.css
  5. +1 −0 web/js/prod.min.js
  6. +6 −5 web/script.part
  7. +5 −3 web/style.part
View
@@ -2,29 +2,22 @@
#display commands
set -x
-SOURCE='./magazine/*'
-TARGET='./magazine.min'
-mkdir $TARGET
-mkdir $TARGET/tmp
-
-cp -rf $SOURCE $TARGET
+#将css和js合并压缩
-node ../tools/combiner $TARGET/head.part -r
-node ../tools/combiner $TARGET/foot.part -r
+TARGET='./web'
-node ../tools/minifier $TARGET/css/libs.min.css $TARGET/tmp/libs.min.css
-node ../tools/minifier $TARGET/css/prod.min.css $TARGET/tmp/prod.min.css
+mkdir $TARGET/tmp
-node ../tools/minifier $TARGET/js/libs.min.js $TARGET/tmp/libs.min.js
-node ../tools/minifier $TARGET/js/prod.min.js $TARGET/tmp/prod.min.js
+node ./tools/combiner $TARGET/style.part
+node ./tools/combiner $TARGET/script.part
-rm -rf $TARGET/css/*.css
-rm -rf $TARGET/js/*.js
+node ./tools/minifier $TARGET/css/prod.min.css $TARGET/tmp/prod.min.css
+node ./tools/minifier $TARGET/js/prod.min.js $TARGET/tmp/prod.min.js
-mv $TARGET/tmp/libs.min.css $TARGET/css/libs.min.css
mv $TARGET/tmp/prod.min.css $TARGET/css/prod.min.css
-mv $TARGET/tmp/libs.min.js $TARGET/js/libs.min.js
mv $TARGET/tmp/prod.min.js $TARGET/js/prod.min.js
+rm -rf $TARGET/tmp
+
sleep 30
View
@@ -34,10 +34,10 @@ var WEBSVR_CONFIG = config.WEBSVR_CONFIG
//Start the WebSvr
var app = WebSvr(WEBSVR_CONFIG)
-//全局默认model
-//app.model({ property: 'value' })
+//全局默认model: debug 为 true时使用未压缩合并的css/js
+app.model({ debug: WEBSVR_CONFIG.debug })
-//change template engine
+//改变默认模板引擎
//app.engine(require("./doT").compile)
View
@@ -74,6 +74,11 @@ var Combine = function(inputFile, outputFile, removeLines, baseFolder) {
var pickupFiles = function(line) {
var formatLine = line.trim().toLowerCase()
+ if (formatLine.indexOf('<!--#output=end-->') > -1) {
+ curCSS = ''
+ curJS = ''
+ }
+
//<!--#output="/css/all.css"-->
if (formatLine.indexOf('<!--#output="') == 0) {
var file = line.substr(13)
@@ -82,13 +87,13 @@ var Combine = function(inputFile, outputFile, removeLines, baseFolder) {
if (file.indexOf('.css') > 0) {
TARGET[file] = []
curCSS = file
- return '<link rel="stylesheet" type="text/css" href="' + file + '">'
+ return removeLines ? '<link rel="stylesheet" type="text/css" href="' + file + '">' : line
}
if (file.indexOf('.js') > 0) {
TARGET[file] = []
curJS = file
- return '<script type="text/javascript" src="' + file + '"></script>'
+ return removeLines ? '<script type="text/javascript" src="' + file + '"></script>' : line
}
return line
@@ -99,7 +104,7 @@ var Combine = function(inputFile, outputFile, removeLines, baseFolder) {
if (url) {
TARGET[curCSS].push(url)
- return ''
+ return removeLines ? '' : line
}
}
@@ -108,7 +113,7 @@ var Combine = function(inputFile, outputFile, removeLines, baseFolder) {
if (url) {
TARGET[curJS].push(url)
- return ''
+ return removeLines ? '' : line
}
}
@@ -125,8 +130,6 @@ var Combine = function(inputFile, outputFile, removeLines, baseFolder) {
return
}
- !outputFile && (outputFile = inputFile.replace('.htm', '.out.htm'))
-
fs.readFile(inputFile, function(err, data) {
var CODES = data.toString()
@@ -143,7 +146,7 @@ var Combine = function(inputFile, outputFile, removeLines, baseFolder) {
mergeCssJs()
- fs.writeFile(outputFile, codes.join(CTRL), function(err) {
+ outputFile && fs.writeFile(outputFile, codes.join(CTRL), function(err) {
if (err) {
console.log(err)
}
@@ -160,7 +163,7 @@ node combiner inputFile ouptFile
*/
var defaultCommand = function() {
var inputFile = process.argv[2]
- , outputFile = process.argv[3]
+ , outputFile = process.argv[3] || ''
, removeLines = process.argv.indexOf('-r') > 0
, baseIdx = process.argv.indexOf('-base')
View
Oops, something went wrong.
View
Oops, something went wrong.
View
@@ -8,13 +8,13 @@ ga('create', 'UA-69796956-1', 'auto');
ga('send', 'pageview');
</script>
-
-<!--#output="/js/libs.min.js"-->
+{{?!it.debug}}
+<script src="/js/prod.min.js"></script>
+{{??}}
+<!--#output="/js/prod.min.js"-->
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/wysihtml5.js"></script>
-
-<!--#output="/js/prod.min.js"-->
<script src="/js/jquery.validate.js"></script>
<script src="/js/jquery.cookie.js"></script>
<script src="/js/bootstrap-wysihtml5.js"></script>
@@ -26,4 +26,5 @@ ga('send', 'pageview');
<script src="/js/string.js"></script>
<script src="/js/jquery.browser.js"></script>
<script src="/js/nprogress.js"></script>
-<script src="/js/ourjs.js"></script>
+<script src="/js/ourjs.js"></script>
+{{?}}
View
@@ -1,14 +1,16 @@
<meta name="author" content="OurJS.org">
<link rel="shortcut icon" href="/favicon.ico">
-<!--#output="/css/libs.min.css"-->
-<link rel="stylesheet" href="/css/bootstrap.css">
-
+{{?!it.debug}}
+<link rel="stylesheet" href="/css/prod.min.css">
+{{??}}
<!--#output="/css/prod.min.css"-->
+<link rel="stylesheet" href="/css/bootstrap.css">
<link rel="stylesheet" href="/css/bootstrap-wysihtml5.css">
<link rel="stylesheet" href="/css/magicsuggest.css">
<link rel="stylesheet" href="/css/ourjs.css">
<!--#output=end-->
+{{?}}
<!--[if lt IE 8]>
<link href="/css/ie7.min.css" rel="stylesheet">

0 comments on commit 42d28b9

Please sign in to comment.