Compare commits

..

2 Commits

@ -2,13 +2,6 @@
这个demo主要是为了快速开发纯静态项目。 这个demo主要是为了快速开发纯静态项目。
利用gulp实现静态页面自动启动服务器、实时刷新、es6转义、scss转css共用公共页面等操作 利用gulp实现静态页面自动启动服务器、实时刷新、es6转义、scss转css共用公共页面等操作
## 使用
```shell
npm install
npm run dev
npm run build
```
## 分支common ## 分支common
普通静态页面 普通静态页面

@ -4,19 +4,14 @@ var connect = require("gulp-connect");
var minifyHtml = require("gulp-minify-html"); //压缩html var minifyHtml = require("gulp-minify-html"); //压缩html
var rename = require("gulp-rename"); //重命名 var rename = require("gulp-rename"); //重命名
var scssToCss = require("gulp-sass")(require('sass')); //scss to css
var minifyCss = require("gulp-minify-css"); //压缩CSS var minifyCss = require("gulp-minify-css"); //压缩CSS
var autoprefixer = require("gulp-autoprefixer"); var autoprefixer = require("gulp-autoprefixer");
var scssToCss = require("gulp-sass")(require('sass')); //scss to css
var clean = require("gulp-clean"); var clean = require("gulp-clean");
var fileinclude = require("gulp-file-include"); var fileinclude = require("gulp-file-include");
var babel = require('gulp-babel');
var webpack = require('webpack-stream');
var sourceMap = require('gulp-sourcemaps');
var webpackConfig = require ("./webpack/webpack.config.js");
// 创建 // 创建
gulp.task("connect", function () { gulp.task("connect", function () {
connect.server({ connect.server({
@ -42,10 +37,11 @@ gulp.task("html", function () {
return gulp return gulp
.src("src/*.html") .src("src/*.html")
.pipe(fileinclude()) //替换头部底部 .pipe(fileinclude()) //替换头部底部
.pipe(minifyHtml({quotes:true})) //执行压缩 .pipe(minifyHtml()) //执行压缩
.pipe(gulp.dest("dist")) .pipe(gulp.dest("dist"))
.pipe(connect.reload()); .pipe(connect.reload());
}); });
gulp.task("scss", function () { gulp.task("scss", function () {
return gulp return gulp
.src("src/static/scss/*.scss") .src("src/static/scss/*.scss")
@ -69,41 +65,18 @@ gulp.task("clean", function () {
gulp.task("watchs", function () { gulp.task("watchs", function () {
gulp.watch("src/*.html", gulp.series("html")); gulp.watch("src/*.html", gulp.series("html"));
gulp.watch("src/tpl/*.html", gulp.series("html"));
gulp.watch("src/static/scss/*.scss", gulp.series( gulp.watch("src/static/scss/*.scss", gulp.series(
"scss", "scss",
gulp.parallel("css") gulp.parallel("css")
)); ));
gulp.watch("src/static/js/*.js", gulp.series("script"));
gulp.watch("gulpfile.js", gulp.series("default"));
}); });
gulp.task('script', () => {
return gulp.src('src/static/js/*.js')
.pipe( sourceMap.init() )
.pipe(babel({
presets: ['@babel/preset-env']
}))
.pipe(webpack(webpackConfig))
.pipe(sourceMap.write())
.pipe(gulp.dest('dist/static/js/'))
.pipe(connect.reload()); //更新;
});
gulp.task("lib", function () {
return gulp
.src("src/static/lib/*.js")
.pipe(gulp.dest("dist/static/lib/"))
.pipe(connect.reload()); //更新;
});
gulp.task( gulp.task(
"default", "default",
gulp.series( gulp.series(
"clean", "clean",
"scss", "scss",
gulp.parallel("html","lib","script", "css"), gulp.parallel("html", "css"),
gulp.parallel("connect", "watchs") gulp.parallel("connect", "watchs")
) )
); );
@ -112,7 +85,6 @@ gulp.task(
"build", "build",
gulp.series( gulp.series(
"clean", "clean",
"scss", gulp.parallel("html", "css")
gulp.parallel("html","lib","script", "css")
) )
); );

13986
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,10 +1,9 @@
{ {
"name": "glup-static-html-demo-es6-scss", "name": "gulp-static-html-scss-demo",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"script": "node --max_old_space_size=8096 node_modules/gulp-cli/bin/gulp.js script",
"serve": "node --max_old_space_size=8096 node_modules/gulp-cli/bin/gulp.js", "serve": "node --max_old_space_size=8096 node_modules/gulp-cli/bin/gulp.js",
"build": "node --max_old_space_size=8096 node_modules/gulp-cli/bin/gulp.js build" "build": "node --max_old_space_size=8096 node_modules/gulp-cli/bin/gulp.js build"
}, },
@ -21,23 +20,18 @@
"author": "ppst", "author": "ppst",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@babel/core": "^7.17.10",
"@babel/preset-env": "^7.17.10",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-autoprefixer": "^8.0.0", "gulp-autoprefixer": "^8.0.0",
"gulp-babel": "^8.0.0",
"gulp-clean": "^0.4.0", "gulp-clean": "^0.4.0",
"gulp-connect": "^5.7.0", "gulp-connect": "^5.7.0",
"gulp-file-include": "^2.3.0", "gulp-file-include": "^2.3.0",
"gulp-minify-css": "^1.2.4", "gulp-minify-css": "^1.2.4",
"gulp-minify-html": "^1.0.6", "gulp-minify-html": "^1.0.6",
"gulp-rename": "^2.0.0", "gulp-rename": "^2.0.0"
"webpack-stream": "^7.0.0"
}, },
"dependencies": { "dependencies": {
"gulp-cli": "^2.3.0", "gulp-cli": "^2.3.0",
"gulp-sass": "^5.1.0", "gulp-sass": "^5.1.0",
"gulp-sourcemaps": "^3.0.0", "sass": "^1.50.1"
"sass": "^1.51.0"
} }
} }

@ -1,23 +1,15 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh"> <html lang="zh">
<head>
<head>
@@include('./tpl/header.html') @@include('./tpl/header.html')
<script src="./static/lib/d3@6.js"></script> </head>
<script src="./static/lib/markmap-view.js"></script>
<script src="./static/js/main.js"></script>
<style>
.markmap-svg{
width: calc(100vw - 40px);
height: calc(100vh - 66px);
}
</style>
</head>
<body> <body>
@@include('./tpl/nav.html')
<section> <section>
<svg id="markmap" class="markmap-svg"></svg> @@include('./tpl/empty.html')
</section> </section>
@@include('./tpl/footer.html') @@include('./tpl/footer.html')
</body> </body>
</html>
</html>

@ -1,7 +1,4 @@
@charset "UTF-8"; @charset "UTF-8";
/* 背景颜色 */
/* 字体 */
/*普通字体颜色*/
/* 重置样式 */ /* 重置样式 */
html { html {
font-family: sans-serif; font-family: sans-serif;
@ -15,82 +12,25 @@ body {
a:link, a:visited, a:hover, a:active { a:link, a:visited, a:hover, a:active {
text-decoration: none; text-decoration: none;
color: #5bbe8e; color: #171a2e;
}
.empty-box {
width: 400px;
height: 100vh;
margin: 0 auto;
} }
/* 底部 */ /* 底部 */
.footer-box { .footer-box {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; height: 60px;
position: fixed; background-color: #171a2e;
bottom: 0;
left: 0;
right: 0;
height: 30px;
background-color: #5bbe8e;
} }
.footer-box .content { .footer-box .content {
font-size: 12px; margin-top: 20px;
font-size: 14px;
color: #fff; color: #fff;
}
/* 头部 */
.header {
height: 40px;
line-height: 40px;
background-color: #fff;
color: #5bbe8e;
box-shadow: 0 4px 4px #f9f9fc;
}
.header .box {
display: flex;
justify-content: space-around;
align-items: center;
padding: 0 10%;
}
.header .box .logo {
font-size: 16px;
}
.header .box a:link, .header .box a:visited, .header .box a:hover, .header .box a:active {
color: #5bbe8e;
}
.header .opr-box {
display: flex;
align-items: center;
color: #5bbe8e;
}
.header .opr-box .item {
font-size: 16px;
margin-right: 10px;
}
/* 内容 */
/* 弹层 */
.mark-box {
display: none;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1;
}
.mark-box .dialog-box {
width: 30%;
height: 400px;
background-color: #fff;
border: 1px solid #f9f9fc;
border-radius: 10px;
}
.show-dialog {
display: flex;
justify-content: center;
align-items: center;
}
.hide-dialog {
display: none;
} }

@ -1,4 +0,0 @@
@charset "UTF-8";
/* 背景颜色 */
/* 字体 */
/*普通字体颜色*/

@ -1 +0,0 @@
// 无需转换

@ -14,52 +14,25 @@ html {
color: $common-font-color; color: $common-font-color;
} }
/* 底部 */ .empty-box{
.footer-box { width: 400px;
display: flex; height: 100vh;
justify-content: center; margin: 0 auto;
align-items: center;
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 30px;
background-color:#5bbe8e;;
}
.footer-box .content {
font-size: $small-font-size;
color: #fff;
}
/* 头部 */
.header{
height: 40px;
line-height: 40px;
background-color: #fff;
color: $common-font-color;
box-shadow: 0 4px 4px #f9f9fc;
.box{
display: flex;
justify-content: space-around;
align-items: center;
padding: 0 10%;
.logo {
font-size: 16px;
}
a:link,a:visited,a:hover,a:active {
color: $common-font-color;
}
} }
.opr-box{
/* 底部 */
.footer-box {
display: flex; display: flex;
align-items: center; justify-content: center;
color: $common-font-color; height: 60px;
.item{ background-color: $footer-bg-color;
font-size: $medium-font-size;
margin-right: 10px;
}
} }
}
.footer-box .content {
margin-top: 20px;
font-size: 14px;
color: $footer-color;
}

@ -1,7 +1,6 @@
/* 背景颜色 */ /* 背景颜色 */
$body-bg-color: #fff; $body-bg-color: #fff;
$footer-bg-color:#5bbe8e; $footer-bg-color:#171a2e;
/* 字体 */ /* 字体 */
@ -11,5 +10,5 @@ $medium-font-size:16px;
$small-font-size:12px; $small-font-size:12px;
$mini-font-size:8px; $mini-font-size:8px;
$common-font-color:#5bbe8e;/*普通字体颜色*/ $common-font-color:#171a2e;/*普通字体颜色*/
$footer-color:#fff; $footer-color:#fff;

File diff suppressed because one or more lines are too long

@ -1,10 +0,0 @@
<header class="header">
<div class="box">
<div class="logo item"><a href="/">MARKMAP</a></div>
<div class="opr-box">
<div class="item open-new-dialog" type="new">新建目录</div>
</div>
</div>
</header>

@ -1,11 +0,0 @@
module.exports = {
entry: {
main: './src/static/js/main.js',
index: './src/static/js/index.js'
},
output: {
filename: '[name].js',
path: __dirname + '/dist'
},
}
Loading…
Cancel
Save