Skip to content

Commit

Permalink
build: tree-shaking with preserveModules
Browse files Browse the repository at this point in the history
  • Loading branch information
jpntex committed Nov 4, 2023
1 parent 762b2d6 commit 4076456
Show file tree
Hide file tree
Showing 57 changed files with 1,786 additions and 1,580 deletions.
6 changes: 6 additions & 0 deletions .changeset/poor-planes-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@indielayer/create-ui": minor
"@indielayer/ui": minor
---

build: tree-shaking with preserveModules
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ packages/ui/lib
packages/create-ui/outfile.cjs
packages/docs/dist
packages/create-ui/templates
packages/ui/vite.config.ts
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
publish-branch=main
shamefully-hoist=true
shell-emulator=true
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@changesets/cli": "^2.26.2",
"@changesets/get-github-info": "^0.5.2",
"@indielayer/eslint-config-vue": "^3.3.1",
"eslint": "^8.52.0",
"eslint": "^8.53.0",
"is-ci": "^3.0.1",
"lint-staged": "^13.3.0",
"simple-git-hooks": "^2.9.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/create-ui/templates/nuxt/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"@types/node": "^18",
"@vueuse/core": "^10.2.0",
"autoprefixer": "^10.4.8",
"nuxt": "^3.6.1",
"ramda": "^0.28.0",
"nuxt": "^3.7.4",
"tailwindcss": "^3.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/create-ui/templates/vue/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"autoprefixer": "^10.4.14",
"postcss": "^8.4.24",
"tailwindcss": "^3.3.2",
"vite": "^4.3.9"
"vite": "^4.4.11"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"@cypress/vite-dev-server": "^5.0.5",
"@cypress/vue": "^5.0.5",
"cypress": "^12.16.0",
"vite": "^4.3.9"
"vite": "^4.4.11"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "nuxt-demo",
"name": "demo-nuxt",
"private": true,
"scripts": {
"build": "nuxt build",
Expand All @@ -14,7 +14,7 @@
"@types/node": "^18",
"autoprefixer": "^10.4.0",
"eslint": "^8.43.0",
"nuxt": "^3.6.1",
"nuxt": "^3.7.4",
"postcss": "^8.4.24",
"tailwindcss": "^3.3.2"
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions packages/demo-vue/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
root: true,
extends: [
'@indielayer/eslint-config-vue',
],
env: {
'vue/setup-compiler-macros': true,
},
}
29 changes: 29 additions & 0 deletions packages/demo-vue/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
stats.html
4 changes: 4 additions & 0 deletions packages/demo-vue/.stylelintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['@indielayer/stylelint-config'],
}
40 changes: 40 additions & 0 deletions packages/demo-vue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# vue-3-bundle

This template should help get you started developing with Vue 3 in Vite.

## Recommended IDE Setup

[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

## Type Support for `.vue` Imports in TS

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:

1. Disable the built-in TypeScript Extension
1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.

## Customize configuration

See [Vite Configuration Reference](https://vitejs.dev/config/).

## Project Setup

```sh
npm install
```

### Compile and Hot-Reload for Development

```sh
npm run dev
```

### Type-Check, Compile and Minify for Production

```sh
npm run build
```
1 change: 1 addition & 0 deletions packages/demo-vue/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
13 changes: 13 additions & 0 deletions packages/demo-vue/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions packages/demo-vue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "demo-vue",
"private": true,
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false"
},
"dependencies": {
"@indielayer/ui": "workspace:*",
"vue": "^3.3.4"
},
"devDependencies": {
"@tsconfig/node18": "^18.2.2",
"@types/node": "^18.18.5",
"@vitejs/plugin-vue": "^4.4.0",
"@vitejs/plugin-vue-jsx": "^3.0.2",
"@vue/tsconfig": "^0.4.0",
"npm-run-all2": "^6.1.1",
"postcss": "^8.4.31",
"rollup-plugin-visualizer": "^5.9.2",
"tailwindcss": "^3.3.2",
"typescript": "~5.2.0",
"vite": "^4.4.11",
"vue-tsc": "^1.8.19"
}
}
8 changes: 8 additions & 0 deletions packages/demo-vue/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// postcss.config.js
module.exports = {
plugins: [
require('tailwindcss/nesting'),
require('tailwindcss'),
require('autoprefixer'),
],
}
Binary file added packages/demo-vue/public/favicon.ico
Binary file not shown.
33 changes: 33 additions & 0 deletions packages/demo-vue/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script setup lang="ts">
import { XLink } from '@indielayer/ui'
</script>

<template>
<div class="flex items-center justify-center h-screen bg-[#001e26] dark text-[#accac8] flex-col">
<div class="text-2xl">Welcome!</div>
<div class="mt-6">Documentation links to get you started:</div>
<div class="flex flex-col space-y-8 my-6 text-center">
<x-link
href="https://v3.nuxtjs.org/"
color="emerald"
shadow
external
target="_blank"
>Nuxt 3</x-link>
<x-link
href="https://vuejs.org/"
color="emerald"
shadow
external
target="_blank"
>Vue 3</x-link>
<x-link
href="https://indielayer.com/ui"
color="emerald"
shadow
external
target="_blank"
>Indielayer UI</x-link>
</div>
</div>
</template>
3 changes: 3 additions & 0 deletions packages/demo-vue/src/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
12 changes: 12 additions & 0 deletions packages/demo-vue/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createApp } from 'vue'
import { createUI } from '@indielayer/ui'
import App from './App.vue'
import './main.css'

const app = createApp(App)

const UI = createUI()

app.use(UI)

app.mount('#app')
12 changes: 12 additions & 0 deletions packages/demo-vue/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const indielayer = require('@indielayer/ui/tailwind.preset')

module.exports = {
content: [
'../ui/lib/**/*',
'./App.vue',
],
darkMode: 'class',
presets: [
indielayer(),
],
}
12 changes: 12 additions & 0 deletions packages/demo-vue/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"composite": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
11 changes: 11 additions & 0 deletions packages/demo-vue/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files": [],
"references": [
{
"path": "./tsconfig.node.json"
},
{
"path": "./tsconfig.app.json"
}
]
}
16 changes: 16 additions & 0 deletions packages/demo-vue/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"include": [
"vite.config.*",
"vitest.config.*",
"cypress.config.*",
"nightwatch.conf.*",
"playwright.config.*"
],
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"types": ["node"]
}
}
24 changes: 24 additions & 0 deletions packages/demo-vue/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { visualizer } from 'rollup-plugin-visualizer'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
vueJsx(),
visualizer({
open: true,
gzipSize: true,
brotliSize: true,
}),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
})
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"shiki": "^0.14.3",
"tailwindcss": "^3.3.2",
"typescript": "^5.2.2",
"vite": "^4.3.9",
"vite": "^4.4.11",
"vue-tsc": "^1.8.2"
}
}
1 change: 0 additions & 1 deletion packages/docs/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// postcss.config.js
module.exports = {
plugins: [
// require('postcss-import'),
require('tailwindcss/nesting'),
require('tailwindcss'),
require('autoprefixer'),
Expand Down
6 changes: 3 additions & 3 deletions packages/docs/src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ app.use(UI, {
:snippets="[{
label: 'npm',
lang: 'bash',
code: 'npm install @indielayer/ui ramda @vueuse/core -D'
code: 'npm install @indielayer/ui @vueuse/core -D'
}, {
label: 'yarn',
lang: 'bash',
code: 'yarn add @indielayer/ui ramda @vueuse/core -D'
code: 'yarn add @indielayer/ui @vueuse/core -D'
}, {
label: 'pnpm',
lang: 'bash',
code: 'pnpm add @indielayer/ui ramda @vueuse/core -D'
code: 'pnpm add @indielayer/ui @vueuse/core -D'
}]"
/>
<code-snippet
Expand Down
1 change: 0 additions & 1 deletion packages/ui/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ yarn-error.log*
Thumbs.db
.nuxt
lib
vite.config.ts
1 change: 1 addition & 0 deletions packages/ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ pnpm-debug.log*
*.njsproj
*.sln
*.sw?
stats.html
Loading

0 comments on commit 4076456

Please sign in to comment.