使用gruntjs自动化html构建

时间:2019-10-26 17:48:48

标签: node.js gulp gruntjs

我正在开发具有以下目录结构的标准Web应用

class TodoEvent:

    def __init__(self, title, due_time, remind_time, description):
        self.title = title
        self.due_time = due_time
        self.remind_time = remind_time
        self.description = description
        toDoEvents[self.title] = self
        self.timer = QTimer(self)
        self.timer.setSingleShot(True)
        self.timer.timeout.connect(self.showReminder)
        self.timer.setTimerType(Qt.PreciseTimer)
        self.change_remind_time(remind_time)

    def change_title(self, new_title):
        self.title = new_title

    def change_due_time(self, new_due_time):
        self.due_time = new_due_time

    def change_remind_time(self, new_remind_time):
        self.remind_time = new_remind_time
        self.timer.start(QDateTime.currentDateTime().msecsTo(self.remind_time))

    def change_description(self, new_description):
        self.description = new_description

    def showReminder(self):
        toaster = ToastNotifier()
        toaster.show_toast(self.title, self.description, threaded=True, icon_path=None, duration=8)

event1 = TodoEvent("test", 
                   QDateTime(2019, 10, 26, 1, 18), 
                   QDateTime(2019, 10, 26, 1, 18), 
                   "test description")

/? app ⊢ index.html ⊢ /? js ⊢ app.min.js ⊢ /? css ⊢ app.min.css ⊢ /? dev ⊢ index.html ⊢ /? js ⊢ app1.js ⊢ app2.js ⊢ /? css ⊢ app1.css ⊢ app2.css 脚本可对gruntjs/dev/js/*.js文件进行丑化,合并和缩小,然后将它们写入顶级文件夹,以准备包含在/dev/css/*.css中。我也想不出如何自动处理/index.html的方法,以便也能使用所有最新更改进行更新,并写出到根级别/dev/index.html。自动化的最简单方法是什么?

我为/index.html找到了https://www.npmjs.com/package/gulp-html-replace,但是我找不到与gulpjs类似的东西

更新:我决定从gruntjs转到gruntjs,因为据我看来,该文献记录得更好。

Update2 :请参见下面的答案

1 个答案:

答案 0 :(得分:0)

万一其他人遇到这个问题,这就是我用gulpjs解决的方法

const { parallel, src, dest } = require('gulp');

const htmlreplace = require('gulp-html-replace');
const cssmin = require('gulp-cssmin');
const concat = require('gulp-concat');
const terser = require('gulp-terser');

const htmldest = '.';
const cssdest = htmldest + '/css';
const jsdest = htmldest + '/js';

const finalcss = 'app.min.css';
const finaljs = 'app.min.js';

function docss() {
    return src('dev/css/*.css')
        .pipe(cssmin())
        .pipe(concat(finalcss))
        .pipe(dest(cssdest));
}

function dohtml() {
    return src('dev/index.html')
        .pipe(htmlreplace({
            'css': `css/${finalcss}`,
            'js': `js/${finaljs}`
        }))
        .pipe(dest(htmldest));
}

function dojs(){
  return src('dev/js/*.js')
    .pipe(terser())
    .pipe(concat(finaljs))
    .pipe(dest(jsdest));
}

exports.default = parallel(docss, dohtml, dojs);