@weapp-core/init 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -307,6 +307,107 @@ function createContext() {
307
307
  };
308
308
  }
309
309
 
310
+ // src/gitignore.ts
311
+ function getDefaultGitignore() {
312
+ return `# dependencies
313
+ node_modules
314
+ .pnp
315
+ .pnp.js
316
+
317
+ # testing
318
+ coverage
319
+
320
+ # next.js
321
+ .next/
322
+ out/
323
+ build
324
+
325
+ # misc
326
+ .DS_Store
327
+ *.pem
328
+
329
+ # debug
330
+ npm-debug.log*
331
+ yarn-debug.log*
332
+ yarn-error.log*
333
+ .pnpm-debug.log*
334
+
335
+ # local env files
336
+ .env.local
337
+ .env.development.local
338
+ .env.test.local
339
+ .env.production.local
340
+
341
+ # turbo
342
+ .turbo
343
+
344
+ dist
345
+ vite.config.ts.timestamp-*.mjs`;
346
+ }
347
+
348
+ // src/tsconfigJson.ts
349
+ function getDefaultTsconfigJson() {
350
+ return {
351
+ compilerOptions: {
352
+ target: "ES2020",
353
+ jsx: "preserve",
354
+ lib: [
355
+ "ES2020",
356
+ "DOM",
357
+ "DOM.Iterable"
358
+ ],
359
+ useDefineForClassFields: true,
360
+ baseUrl: ".",
361
+ module: "ESNext",
362
+ moduleResolution: "bundler",
363
+ paths: {
364
+ "@/*": [
365
+ "./*"
366
+ ]
367
+ },
368
+ resolveJsonModule: true,
369
+ types: [
370
+ "miniprogram-api-typings"
371
+ ],
372
+ allowImportingTsExtensions: true,
373
+ allowJs: true,
374
+ strict: true,
375
+ noFallthroughCasesInSwitch: true,
376
+ noUnusedLocals: true,
377
+ noUnusedParameters: true,
378
+ noEmit: true,
379
+ isolatedModules: true,
380
+ skipLibCheck: true
381
+ },
382
+ references: [
383
+ {
384
+ path: "./tsconfig.node.json"
385
+ }
386
+ ],
387
+ include: [
388
+ "**/*.ts",
389
+ "**/*.js"
390
+ ],
391
+ exclude: [
392
+ "node_modules",
393
+ "dist"
394
+ ]
395
+ };
396
+ }
397
+ function getDefaultTsconfigNodeJson(include) {
398
+ return {
399
+ compilerOptions: {
400
+ composite: true,
401
+ module: "ESNext",
402
+ moduleResolution: "bundler",
403
+ strict: true,
404
+ allowSyntheticDefaultImports: true,
405
+ skipLibCheck: true
406
+ },
407
+ include
408
+ };
409
+ }
410
+
310
411
  // src/index.ts
311
412
  var __dirname = path.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
312
413
  var ctx = createContext();
@@ -483,52 +584,7 @@ async function initTsJsonFiles(options) {
483
584
  const tsNodeJsonFilename = ctx.tsconfigNode.name = "tsconfig.node.json";
484
585
  const tsNodeJsonFilePath = ctx.tsconfigNode.path = path.resolve(root, tsNodeJsonFilename);
485
586
  if (write) {
486
- const tsJsonValue = {
487
- compilerOptions: {
488
- target: "ES2020",
489
- jsx: "preserve",
490
- lib: [
491
- "ES2020",
492
- "DOM",
493
- "DOM.Iterable"
494
- ],
495
- useDefineForClassFields: true,
496
- baseUrl: ".",
497
- module: "ESNext",
498
- moduleResolution: "bundler",
499
- paths: {
500
- "@/*": [
501
- "./*"
502
- ]
503
- },
504
- resolveJsonModule: true,
505
- types: [
506
- "miniprogram-api-typings"
507
- ],
508
- allowImportingTsExtensions: true,
509
- allowJs: true,
510
- strict: true,
511
- noFallthroughCasesInSwitch: true,
512
- noUnusedLocals: true,
513
- noUnusedParameters: true,
514
- noEmit: true,
515
- isolatedModules: true,
516
- skipLibCheck: true
517
- },
518
- references: [
519
- {
520
- path: "./tsconfig.node.json"
521
- }
522
- ],
523
- include: [
524
- "**/*.ts",
525
- "**/*.js"
526
- ],
527
- exclude: [
528
- "node_modules",
529
- "dist"
530
- ]
531
- };
587
+ const tsJsonValue = getDefaultTsconfigJson();
532
588
  if (write) {
533
589
  await import_fs_extra.default.outputJSON(
534
590
  tsJsonFilePath,
@@ -541,19 +597,9 @@ async function initTsJsonFiles(options) {
541
597
  import_logger.default.log(`\u2728 \u8BBE\u7F6E ${tsJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
542
598
  }
543
599
  ctx.tsconfig.value = tsJsonValue;
544
- const tsJsonNodeValue = {
545
- compilerOptions: {
546
- composite: true,
547
- module: "ESNext",
548
- moduleResolution: "bundler",
549
- strict: true,
550
- allowSyntheticDefaultImports: true,
551
- skipLibCheck: true
552
- },
553
- include: [
554
- ctx.viteConfig.name
555
- ]
556
- };
600
+ const tsJsonNodeValue = getDefaultTsconfigNodeJson([
601
+ ctx.viteConfig.name
602
+ ]);
557
603
  if (write) {
558
604
  await import_fs_extra.default.outputJSON(tsNodeJsonFilePath, tsJsonNodeValue, {
559
605
  encoding: "utf8",
@@ -567,40 +613,7 @@ async function initTsJsonFiles(options) {
567
613
  async function updateGitIgnore(options) {
568
614
  const { root, write = true } = options;
569
615
  const filepath = path.resolve(root, ".gitignore");
570
- const data = `# dependencies
571
- node_modules
572
- .pnp
573
- .pnp.js
574
-
575
- # testing
576
- coverage
577
-
578
- # next.js
579
- .next/
580
- out/
581
- build
582
-
583
- # misc
584
- .DS_Store
585
- *.pem
586
-
587
- # debug
588
- npm-debug.log*
589
- yarn-debug.log*
590
- yarn-error.log*
591
- .pnpm-debug.log*
592
-
593
- # local env files
594
- .env.local
595
- .env.development.local
596
- .env.test.local
597
- .env.production.local
598
-
599
- # turbo
600
- .turbo
601
-
602
- dist
603
- vite.config.ts.timestamp-*.mjs`;
616
+ const data = getDefaultGitignore();
604
617
  if (write) {
605
618
  await import_fs_extra.default.outputFile(filepath, data, {
606
619
  encoding: "utf8"
@@ -624,6 +637,12 @@ async function createProject(targetDir = "", templateDirName = "default") {
624
637
  const targetTemplateDir = path.resolve(__dirname, "../templates", templateDirName);
625
638
  if (await import_fs_extra.default.exists(targetTemplateDir)) {
626
639
  await import_fs_extra.default.copy(targetTemplateDir, targetDir);
640
+ const pkgJsonPath = path.resolve(targetTemplateDir, "package.json");
641
+ const pkgJson = await import_fs_extra.default.readJson(pkgJsonPath);
642
+ if (pkgJson.devDependencies) {
643
+ pkgJson.devDependencies["weapp-vite"] = "latest";
644
+ }
645
+ await import_fs_extra.default.writeJson(path.resolve(targetDir, "package.json"), pkgJson, { spaces: 2 });
627
646
  import_logger.default.log(`\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!`);
628
647
  } else {
629
648
  import_logger.default.warn(`\u6CA1\u6709\u627E\u5230 ${templateDirName} \u6A21\u677F!`);
package/dist/index.js CHANGED
@@ -261,6 +261,107 @@ function createContext() {
261
261
  };
262
262
  }
263
263
 
264
+ // src/gitignore.ts
265
+ function getDefaultGitignore() {
266
+ return `# dependencies
267
+ node_modules
268
+ .pnp
269
+ .pnp.js
270
+
271
+ # testing
272
+ coverage
273
+
274
+ # next.js
275
+ .next/
276
+ out/
277
+ build
278
+
279
+ # misc
280
+ .DS_Store
281
+ *.pem
282
+
283
+ # debug
284
+ npm-debug.log*
285
+ yarn-debug.log*
286
+ yarn-error.log*
287
+ .pnpm-debug.log*
288
+
289
+ # local env files
290
+ .env.local
291
+ .env.development.local
292
+ .env.test.local
293
+ .env.production.local
294
+
295
+ # turbo
296
+ .turbo
297
+
298
+ dist
299
+ vite.config.ts.timestamp-*.mjs`;
300
+ }
301
+
302
+ // src/tsconfigJson.ts
303
+ function getDefaultTsconfigJson() {
304
+ return {
305
+ compilerOptions: {
306
+ target: "ES2020",
307
+ jsx: "preserve",
308
+ lib: [
309
+ "ES2020",
310
+ "DOM",
311
+ "DOM.Iterable"
312
+ ],
313
+ useDefineForClassFields: true,
314
+ baseUrl: ".",
315
+ module: "ESNext",
316
+ moduleResolution: "bundler",
317
+ paths: {
318
+ "@/*": [
319
+ "./*"
320
+ ]
321
+ },
322
+ resolveJsonModule: true,
323
+ types: [
324
+ "miniprogram-api-typings"
325
+ ],
326
+ allowImportingTsExtensions: true,
327
+ allowJs: true,
328
+ strict: true,
329
+ noFallthroughCasesInSwitch: true,
330
+ noUnusedLocals: true,
331
+ noUnusedParameters: true,
332
+ noEmit: true,
333
+ isolatedModules: true,
334
+ skipLibCheck: true
335
+ },
336
+ references: [
337
+ {
338
+ path: "./tsconfig.node.json"
339
+ }
340
+ ],
341
+ include: [
342
+ "**/*.ts",
343
+ "**/*.js"
344
+ ],
345
+ exclude: [
346
+ "node_modules",
347
+ "dist"
348
+ ]
349
+ };
350
+ }
351
+ function getDefaultTsconfigNodeJson(include) {
352
+ return {
353
+ compilerOptions: {
354
+ composite: true,
355
+ module: "ESNext",
356
+ moduleResolution: "bundler",
357
+ strict: true,
358
+ allowSyntheticDefaultImports: true,
359
+ skipLibCheck: true
360
+ },
361
+ include
362
+ };
363
+ }
364
+
264
365
  // src/index.ts
265
366
  var __dirname2 = path.dirname(fileURLToPath(import.meta.url));
266
367
  var ctx = createContext();
@@ -437,52 +538,7 @@ async function initTsJsonFiles(options) {
437
538
  const tsNodeJsonFilename = ctx.tsconfigNode.name = "tsconfig.node.json";
438
539
  const tsNodeJsonFilePath = ctx.tsconfigNode.path = path.resolve(root, tsNodeJsonFilename);
439
540
  if (write) {
440
- const tsJsonValue = {
441
- compilerOptions: {
442
- target: "ES2020",
443
- jsx: "preserve",
444
- lib: [
445
- "ES2020",
446
- "DOM",
447
- "DOM.Iterable"
448
- ],
449
- useDefineForClassFields: true,
450
- baseUrl: ".",
451
- module: "ESNext",
452
- moduleResolution: "bundler",
453
- paths: {
454
- "@/*": [
455
- "./*"
456
- ]
457
- },
458
- resolveJsonModule: true,
459
- types: [
460
- "miniprogram-api-typings"
461
- ],
462
- allowImportingTsExtensions: true,
463
- allowJs: true,
464
- strict: true,
465
- noFallthroughCasesInSwitch: true,
466
- noUnusedLocals: true,
467
- noUnusedParameters: true,
468
- noEmit: true,
469
- isolatedModules: true,
470
- skipLibCheck: true
471
- },
472
- references: [
473
- {
474
- path: "./tsconfig.node.json"
475
- }
476
- ],
477
- include: [
478
- "**/*.ts",
479
- "**/*.js"
480
- ],
481
- exclude: [
482
- "node_modules",
483
- "dist"
484
- ]
485
- };
541
+ const tsJsonValue = getDefaultTsconfigJson();
486
542
  if (write) {
487
543
  await fs.outputJSON(
488
544
  tsJsonFilePath,
@@ -495,19 +551,9 @@ async function initTsJsonFiles(options) {
495
551
  logger.log(`\u2728 \u8BBE\u7F6E ${tsJsonFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
496
552
  }
497
553
  ctx.tsconfig.value = tsJsonValue;
498
- const tsJsonNodeValue = {
499
- compilerOptions: {
500
- composite: true,
501
- module: "ESNext",
502
- moduleResolution: "bundler",
503
- strict: true,
504
- allowSyntheticDefaultImports: true,
505
- skipLibCheck: true
506
- },
507
- include: [
508
- ctx.viteConfig.name
509
- ]
510
- };
554
+ const tsJsonNodeValue = getDefaultTsconfigNodeJson([
555
+ ctx.viteConfig.name
556
+ ]);
511
557
  if (write) {
512
558
  await fs.outputJSON(tsNodeJsonFilePath, tsJsonNodeValue, {
513
559
  encoding: "utf8",
@@ -521,40 +567,7 @@ async function initTsJsonFiles(options) {
521
567
  async function updateGitIgnore(options) {
522
568
  const { root, write = true } = options;
523
569
  const filepath = path.resolve(root, ".gitignore");
524
- const data = `# dependencies
525
- node_modules
526
- .pnp
527
- .pnp.js
528
-
529
- # testing
530
- coverage
531
-
532
- # next.js
533
- .next/
534
- out/
535
- build
536
-
537
- # misc
538
- .DS_Store
539
- *.pem
540
-
541
- # debug
542
- npm-debug.log*
543
- yarn-debug.log*
544
- yarn-error.log*
545
- .pnpm-debug.log*
546
-
547
- # local env files
548
- .env.local
549
- .env.development.local
550
- .env.test.local
551
- .env.production.local
552
-
553
- # turbo
554
- .turbo
555
-
556
- dist
557
- vite.config.ts.timestamp-*.mjs`;
570
+ const data = getDefaultGitignore();
558
571
  if (write) {
559
572
  await fs.outputFile(filepath, data, {
560
573
  encoding: "utf8"
@@ -578,6 +591,12 @@ async function createProject(targetDir = "", templateDirName = "default") {
578
591
  const targetTemplateDir = path.resolve(__dirname2, "../templates", templateDirName);
579
592
  if (await fs.exists(targetTemplateDir)) {
580
593
  await fs.copy(targetTemplateDir, targetDir);
594
+ const pkgJsonPath = path.resolve(targetTemplateDir, "package.json");
595
+ const pkgJson = await fs.readJson(pkgJsonPath);
596
+ if (pkgJson.devDependencies) {
597
+ pkgJson.devDependencies["weapp-vite"] = "latest";
598
+ }
599
+ await fs.writeJson(path.resolve(targetDir, "package.json"), pkgJson, { spaces: 2 });
581
600
  logger.log(`\u2728 \u521B\u5EFA\u6A21\u677F\u6210\u529F!`);
582
601
  } else {
583
602
  logger.warn(`\u6CA1\u6709\u627E\u5230 ${templateDirName} \u6A21\u677F!`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-core/init",
3
3
  "type": "module",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "description": "@weapp-core/init",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -2,6 +2,7 @@
2
2
  "name": "weapp-vite-tailwindcss-template",
3
3
  "type": "module",
4
4
  "version": "1.0.0",
5
+ "private": true,
5
6
  "description": "原生微信小程序 weapp-vite + tailwindcss 模板",
6
7
  "author": "ice breaker <1324318532@qq.com>",
7
8
  "license": "MIT",
@@ -22,6 +23,8 @@
22
23
  "postinstall": "weapp-tw patch"
23
24
  },
24
25
  "devDependencies": {
26
+ "@egoist/tailwindcss-icons": "^1.8.1",
27
+ "@iconify-json/mdi": "^1.2.1",
25
28
  "autoprefixer": "^10.4.20",
26
29
  "miniprogram-api-typings": "latest",
27
30
  "postcss": "^8.4.47",
@@ -2,6 +2,6 @@
2
2
  "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
3
3
  "projectname": "weapp-vite-tailwindcss-template",
4
4
  "setting": {
5
- "compileHotReLoad": true
5
+ "compileHotReLoad": false
6
6
  }
7
7
  }
@@ -6,14 +6,6 @@
6
6
  ],
7
7
  "window": {},
8
8
  "style": "v2",
9
- "rendererOptions": {
10
- "skyline": {
11
- "defaultDisplayBlock": true,
12
- "disableABTest": true,
13
- "sdkVersionBegin": "3.0.0",
14
- "sdkVersionEnd": "15.255.255"
15
- }
16
- },
17
9
  "componentFramework": "glass-easel",
18
10
  "sitemapLocation": "sitemap.json",
19
11
  "lazyCodeLoading": "requiredComponents"
@@ -1,18 +1,6 @@
1
- // app.ts
2
1
  App({
3
2
  globalData: {},
4
3
  onLaunch() {
5
- // 展示本地存储能力
6
- const logs = wx.getStorageSync('logs') || []
7
- logs.unshift(Date.now())
8
- wx.setStorageSync('logs', logs)
9
4
 
10
- // 登录
11
- wx.login({
12
- success: (res) => {
13
- console.log(res.code)
14
- // 发送 res.code 到后台换取 openId, sessionKey, unionId
15
- },
16
- })
17
5
  },
18
6
  })
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "$schema": "https://vite.icebreaker.top/component.json",
3
3
  "component": true,
4
+ // 组件需要设置成 "apply-shared" 才能使用 app.wxss 里的全局样式
4
5
  "styleIsolation": "apply-shared",
5
6
  "usingComponents": {}
6
7
  }
@@ -2,5 +2,6 @@
2
2
  "$schema": "https://vite.icebreaker.top/page.json",
3
3
  "usingComponents": {
4
4
  "navigation-bar": "/components/navigation-bar/navigation-bar"
5
- }
5
+ },
6
+ "navigationBarTitleText": "初始模板"
6
7
  }
@@ -1,3 +1,17 @@
1
- Component({
2
-
1
+ Page({
2
+ data: {
3
+ mode: 'light',
4
+ },
5
+ switchMode() {
6
+ if (this.data.mode === 'light') {
7
+ this.setData({
8
+ mode: 'dark',
9
+ })
10
+ }
11
+ else {
12
+ this.setData({
13
+ mode: 'light',
14
+ })
15
+ }
16
+ },
3
17
  })
@@ -1 +1,12 @@
1
- <view class="bg-slate-800 text-white">weapp-vite + weapp-tailwindcss</view>
1
+ <view class="min-h-screen {{ mode === 'light'?'bg-gray-100':'bg-gray-900' }} transition-colors duration-500">
2
+ <view class="flex flex-col items-center pt-20 space-y-10">
3
+ <view class="flex space-x-8">
4
+ <view class="w-24 h-24 bg-[url(https://vite.icebreaker.top/logo.png)] bg-[length:100%_100%] bg-no-repeat"></view>
5
+ <view class="w-32 h-24 bg-[url(https://vite.icebreaker.top/tw-logo.png)] bg-[length:100%_100%] bg-no-repeat"></view>
6
+ </view>
7
+ <view class="bg-gradient-to-r from-green-400 to-sky-400 bg-clip-text text-xl font-extrabold text-transparent underline">
8
+ weapp-vite & weapp-tailwindcss
9
+ </view>
10
+ <view class="{{ mode === 'light' ? 'i-mdi-moon-waxing-crescent':'i-mdi-weather-sunny text-white' }} text-8xl" bind:tap="switchMode"></view>
11
+ </view>
12
+ </view>
@@ -1,4 +1,5 @@
1
1
  import type { Config } from 'tailwindcss'
2
+ import { getIconCollections, iconsPlugin } from '@egoist/tailwindcss-icons'
2
3
 
3
4
  export default <Config>{
4
5
  content: [
@@ -8,7 +9,11 @@ export default <Config>{
8
9
  theme: {
9
10
  extend: {},
10
11
  },
11
- plugins: [],
12
+ plugins: [
13
+ iconsPlugin({
14
+ collections: getIconCollections(['mdi']),
15
+ }),
16
+ ],
12
17
  corePlugins: {
13
18
  // 小程序不需要 preflight 和 container,因为这主要是给 h5 的,如果你要同时开发小程序和 h5 端,你应该使用环境变量来控制它
14
19
  preflight: false,