UNPKG

@plugin-light/project-config-uni-vite

Version:

开箱即用的项目配置,适用于 uni-app Vue3.x 项目

46 lines (33 loc) 984 B
const path = require('path'); const { readFileSync, writeFileSync } = require('t-comm'); const dotenv = require('dotenv'); const dotenvExpand = require('dotenv-expand'); const gulp = require('gulp'); const myEnv = dotenv.config({ path: '.env.local' }); dotenvExpand.expand(myEnv); function debounce(fn, delay) { let timeout; const newFn = function (...args) { clearTimeout(timeout); const timerFn = () => fn.apply(this, args); timeout = setTimeout(timerFn, delay); }; newFn.cancel = function () { clearTimeout(timeout); }; return newFn; } function changeMainTS() { const { UNI_INPUT_DIR } = process.env; const entrance = path.resolve(UNI_INPUT_DIR, 'main.ts'); writeFileSync(entrance, readFileSync(entrance)); console.log('[Y]'); } function watchSass(watch = './src/**/*.scss') { const realChangeMainTS = debounce(changeMainTS, 100); gulp.watch(watch, (cb) => { realChangeMainTS(); cb(); }); } module.exports = watchSass;