chore: 优化打包工具,修复 IE11 下的若干报错 (#2920)

* build: 修复 git 在 Windows 中的换行符转换问题

* fix: 修复 IE11 下的若干异常问题

* build: 优化打包脚本,确保模块正确的顺序

原计划升级 gulp 5(因 npm audit 提示 gulp 4 漏洞),但由于其改动太大,考虑到 v2 已作为 stable 版本,暂时保留现状。

* Update src/modules/laydate.js

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore(laydate): 格式化代码

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
贤心
2025-11-12 15:51:52 +08:00
committed by GitHub
parent 5ab142153b
commit f69f7c9095
6 changed files with 47 additions and 36 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
* text=auto eol=lf

View File

@@ -358,10 +358,7 @@
// 局部自定义标签符
laytpl(
`
<% var job = ["前端工程师"]; %>
<%= d.name %>是一名<%= job[d.index] %>。
`,
'<% var job = ["前端工程师"]; %><%= d.name %>是一名<%= job[d.index] %>。',
{
open: '<%',
close: '%>'

View File

@@ -262,10 +262,13 @@
console.log('beforeClose', data);
// 关闭确认提示
layer.confirm(`确定关闭标签「${this.innerText}」吗?`, function (i) {
tabs.close('demoTabs1', data.index, true); // 强制关闭对应的标签项
layer.close(i); // 关闭确认框
});
layer.confirm(
'确定关闭标签「' + this.innerText + '」吗?',
function (i) {
tabs.close('demoTabs1', data.index, true); // 强制关闭对应的标签项
layer.close(i); // 关闭确认框
}
);
return false; // 阻止标签默认关闭
});

View File

@@ -261,7 +261,7 @@
var dateString = util.toDateString(new Date(), format);
$('#test3').html(dateString);
};
timer = setInterval(() => {
timer = setInterval(function () {
toDateString($('#test2').val());
}, 50);

View File

@@ -9,19 +9,16 @@ const sourcemaps = require('gulp-sourcemaps');
const zip = require('gulp-zip');
const del = require('del');
const minimist = require('minimist');
const yargs = require('yargs');
const pkg = require('./package.json');
// 基础配置
const config = {
// 头部注释
comment: [
'/** v<%= pkg.version %> | <%= pkg.license %> Licensed */<%= js %>',
{ pkg: pkg, js: ';' }
],
comment: `/** v${pkg.version} | ${pkg.license} Licensed */;`,
// 全部模块
modules:
'lay,i18n,laytpl,laypage,laydate,jquery,component,layer,util,dropdown,slider,colorpicker,tab,nav,breadcrumb,progress,collapse,element,upload,form,table,treeTable,tabs,tree,transfer,carousel,rate,flow,code'
'layui.all,lay,i18n,laytpl,laypage,laydate,jquery,component,layer,util,dropdown,slider,colorpicker,tab,nav,breadcrumb,progress,collapse,element,upload,form,table,treeTable,tabs,tree,transfer,carousel,rate,flow,code'
};
// 获取参数
@@ -45,7 +42,10 @@ const dest = './dist';
// js
const js = () => {
let src = ['./src/**/{layui,layui.all,' + config.modules + '}.js'];
let src = [
'./src/layui.js',
...config.modules.split(',').map((mod) => `./src/modules/${mod}.js`)
];
return gulp
.src(src)
.pipe(sourcemaps.init())
@@ -58,7 +58,7 @@ const js = () => {
})
)
.pipe(concat('layui.js', { newLine: '' }))
.pipe(header.apply(null, config.comment))
.pipe(header(config.comment))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(dest));
};
@@ -141,10 +141,14 @@ exports.release = gulp.series(
}
);
// helper
exports.help = () => {
let usage = '\nUsage: gulp [options] tasks';
let parser = yargs.usage(usage, {
/**
* 显示 gulp tasks 命令行帮助
* 由于 gulp-cli 依赖了 yargs此处直接使用
* @returns
*/
exports.helper = () => {
let usage = '\nUsage: gulp [options] tasks\n';
let parser = require('yargs').options({
dest: {
type: 'string',
desc: '自定义输出路径'
@@ -154,14 +158,14 @@ exports.help = () => {
desc: '生成一个带版本号的文件夹'
}
});
console.log(usage);
parser.showHelp(console.log);
console.log(
[
'Tasks:',
'\nTasks:',
' default 默认任务',
' release 发行任务',
' cp 将 dist 目录复制一份到参数 --dest 指向的目录'
' cp 将 dist 目录复制一份到参数 --dest 指向的目录'
].join('\n'),
'\n\nExamples:\n gulp cp --dest ./v',
'\n'

View File

@@ -188,18 +188,24 @@ layui.define(['lay', 'i18n'], function (exports) {
YearBeforeMonthLocale.indexOf(options.lang) > -1
);
} else {
var formatter = new Intl.DateTimeFormat(options.lang, {
year: 'numeric',
month: 'short'
});
var parts = formatter.formatToParts(new Date(1970, 0));
var order = [];
parts.map(function (part) {
if (part.type === 'year' || part.type === 'month') {
order.push(part.type);
}
});
that.i18nMessages.monthBeforeYear = order[0] === 'month';
try {
var formatter = new Intl.DateTimeFormat(options.lang, {
year: 'numeric',
month: 'short'
});
var parts = formatter.formatToParts(new Date(1970, 0));
var order = [];
parts.map(function (part) {
if (part.type === 'year' || part.type === 'month') {
order.push(part.type);
}
});
that.i18nMessages.monthBeforeYear = order[0] === 'month';
} catch (e) {
that.i18nMessages.monthBeforeYear = !(
YearBeforeMonthLocale.indexOf(options.lang) > -1
);
}
}
}