ts-npm-init
Version:
创建TypeScript NPM库的现代化模板
106 lines (96 loc) • 3.53 kB
HTML
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NPM包测试页面</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.test-container {
border: 1px solid #ccc;
padding: 20px;
margin-bottom: 20px;
border-radius: 5px;
}
.result {
background-color: #f5f5f5;
padding: 10px;
border-radius: 3px;
white-space: pre-wrap;
margin-top: 10px;
}
button {
padding: 8px 16px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
button:hover {
background-color: #45a049;
}
h1 {
color: #333;
}
h2 {
color: #555;
}
</style>
</head>
<body>
<h1>NPM包测试页面</h1>
<p>这个页面用于测试npm-package-template包的功能</p>
<div class="test-container">
<h2>测试Utils.isEmpty方法</h2>
<button onclick="testIsEmpty()">运行测试</button>
<div id="isEmpty-result" class="result">点击按钮运行测试...</div>
</div>
<div class="test-container">
<h2>测试样式应用</h2>
<div id="style-test">这是一个样式测试元素</div>
<button onclick="testStyles()">应用样式</button>
<div id="style-result" class="result">点击按钮运行测试...</div>
</div>
<!-- 引入打包后的UMD格式库文件 -->
<script src="../node_modules/npm-package-template/dist/index.umd.js"></script>
<script>
// 从全局变量中获取库的导出
const { Utils } = window.npmPackageTemplate || {};
function testIsEmpty() {
if (!Utils) {
document.getElementById('isEmpty-result').textContent = '错误:无法访问Utils类,请确保库正确加载';
return;
}
const results = [
`Utils.isEmpty(null): ${Utils.isEmpty(null)}`,
`Utils.isEmpty(""): ${Utils.isEmpty("")}`,
`Utils.isEmpty([]): ${Utils.isEmpty([])}`,
`Utils.isEmpty({}): ${Utils.isEmpty({})}`,
`Utils.isEmpty("hello"): ${Utils.isEmpty("hello")}`
];
document.getElementById('isEmpty-result').textContent = results.join('\n');
}
function testStyles() {
if (!Utils) {
document.getElementById('style-result').textContent = '错误:无法访问Utils类,请确保库正确加载';
return;
}
try {
const element = document.getElementById('style-test');
// 应用CSS样式
Utils.applyStyles(element, false);
document.getElementById('style-result').textContent = '已应用CSS样式类:example-class';
} catch (error) {
document.getElementById('style-result').textContent = `错误:${error.message}`;
}
}
</script>
</body>
</html>