Skip to content

Commit

Permalink
chore: beta.3 support tree shaking
Browse files Browse the repository at this point in the history
  • Loading branch information
richard1015 committed Mar 4, 2021
1 parent 363ff1c commit 0f8b2ca
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 107 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ node_modules
yarn.lock
package-lock.json
/cache
/src/nutui.ts


# local env files
Expand Down
40 changes: 40 additions & 0 deletions jd/generate-nutui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const package = require('../package.json');
const config = require('../src/config.json');
const path = require('path');
const fs = require('fs');
let importStr = '';
const packages = [];
config.nav.map(item => {
item.packages.forEach(element => {
let { name, show } = element;
if (show) {
importStr += `import ${name} from '/src/packages/${name.toLowerCase()}/index.vue';\n`;
packages.push(name);
}
});
});
let installFunction = `
function install(app: any) {
const packages = [${packages.join(',')}];
packages.forEach((item:any) => {
if (item.install) {
app.use(item);
} else if (item.name) {
app.component(item.name, item);
}
});
}
`;
let fileStr = `
${importStr}
${installFunction}
export { ${packages.join(',')} };
export default { install, version:'${package.version}'};`;
fs.writeFile(
path.resolve(__dirname, '../src/nutui.ts'),
fileStr,
'utf8',
error => {
// logger.success(`${package_config_path} 文件写入成功`);
}
);
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nutui/nutui",
"version": "3.0.0-beta.2",
"version": "3.0.0-beta.3",
"npm": {
"tag": "beta"
},
Expand Down Expand Up @@ -36,14 +36,14 @@
"CHANGELOG.md"
],
"scripts": {
"dev": "tsc && vite --open",
"dev": "rm -rf dist && tsc && npm run generate:file && vite --open",
"build:site": "vite build",
"build": "vite build -c vite.config.build.ts",
"build:ts": "rm -rf dist/es && tsc",
"build": "npm run generate:file && vite build -c vite.config.build.ts",
"serve": "vite preview",
"upload": "yarn build:site && node ./jd/upload.js",
"add": "node jd/createComponentMode.js",
"publish:beta": "npm publish --tag=beta"
"publish:beta": "npm publish --tag=beta",
"generate:file": "node jd/generate-nutui.js"
},
"dependencies": {
"axios": "^0.21.0",
Expand Down Expand Up @@ -108,4 +108,4 @@
"type": "git",
"url": "https://github.com/jdf2e/nutui.git"
}
}
}
16 changes: 8 additions & 8 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"author": "richard1015"
},
{
"name": "collapse",
"name": "Collapse",
"sort": 2,
"cName": "折叠面板",
"type": "component",
Expand All @@ -89,7 +89,7 @@
"author": "Ymm0008"
},
{
"name": "collapse",
"name": "CollapseItem",
"sort": 3,
"cName": "折叠面板-item",
"type": "component",
Expand All @@ -107,7 +107,7 @@
"author": "undo"
},
{
"name": "col",
"name": "Col",
"sort": 5,
"cName": "布局-Col",
"type": "component",
Expand All @@ -116,7 +116,7 @@
"author": "undo"
},
{
"name": "row",
"name": "Row",
"sort": 6,
"cName": "布局-Row",
"type": "component",
Expand Down Expand Up @@ -186,7 +186,7 @@
"sort": 1,
"cName": "模板组件",
"type": "component",
"show": true,
"show": false,
"desc": "组件模板示例",
"author": "richard1015"
},
Expand Down Expand Up @@ -366,7 +366,7 @@
"author": "liqiong43"
},
{
"name": "tab",
"name": "Tab",
"sort": 1,
"cName": "标签组件",
"type": "component",
Expand All @@ -375,7 +375,7 @@
"author": "zhenyulei"
},
{
"name": "menu",
"name": "Menu",
"sort": 2,
"cName": "菜单组件",
"type": "component",
Expand All @@ -384,7 +384,7 @@
"author": "vickyYE"
},
{
"name": "tabbar",
"name": "Tabbar",
"sort": 2,
"cName": "标签栏组件",
"type": "component",
Expand Down
128 changes: 113 additions & 15 deletions src/nutui.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,115 @@
import { version } from '../package.json';
const modules = import.meta.globEager('/src/packages/**/index.vue');
function install(app: any) {
/** webpack */
// const files = require.context('@/packages', true, /index\.vue$/);
// files.keys().forEach(component => {
// const componentEntity = files(component).default;
// app.component(componentEntity.name, componentEntity);
// });
import Button from '/src/packages/button/index.vue';
import Collapse from '/src/packages/collapse/index.vue';
import Layout from '/src/packages/layout/index.vue';
import BackTop from '/src/packages/backtop/index.vue';
import ActionSheet from '/src/packages/actionsheet/index.vue';
import Toast from '/src/packages/toast/index.vue';
import Notify from '/src/packages/notify/index.vue';
import Picker from '/src/packages/picker/index.vue';
import Cell from '/src/packages/cell/index.vue';
import Uploader from '/src/packages/uploader/index.vue';
import Icon from '/src/packages/icon/index.vue';
import Price from '/src/packages/price/index.vue';
import Checkbox from '/src/packages/checkbox/index.vue';
import Swiper from '/src/packages/swiper/index.vue';
import Avatar from '/src/packages/avatar/index.vue';
import Popup from '/src/packages/popup/index.vue';
import Dialog from '/src/packages/dialog/index.vue';
import Radio from '/src/packages/radio/index.vue';
import OverLay from '/src/packages/overlay/index.vue';
import InfiniteLoading from '/src/packages/infiniteloading/index.vue';
import Range from '/src/packages/range/index.vue';
import PullRefresh from '/src/packages/pullrefresh/index.vue';
import Navbar from '/src/packages/navbar/index.vue';
import Tab from '/src/packages/tab/index.vue';
import Menu from '/src/packages/menu/index.vue';
import Tabbar from '/src/packages/tabbar/index.vue';
import InputNumber from '/src/packages/inputnumber/index.vue';
import Input from '/src/packages/input/index.vue';
import Switch from '/src/packages/switch/index.vue';
import Rate from '/src/packages/rate/index.vue';
import Calendar from '/src/packages/calendar/index.vue';
import ShortPassword from '/src/packages/shortpassword/index.vue';
import Address from '/src/packages/address/index.vue';

/** vite */
for (const key in modules) {
const componentEntity = modules[key]?.default;
app.component(componentEntity.name, componentEntity);
}
function install(app: any) {
const packages = [
Button,
Collapse,
Layout,
BackTop,
ActionSheet,
Toast,
Notify,
Picker,
Cell,
Uploader,
Icon,
Price,
Checkbox,
Swiper,
Avatar,
Popup,
Dialog,
Radio,
OverLay,
InfiniteLoading,
Range,
PullRefresh,
Navbar,
Tab,
Menu,
Tabbar,
InputNumber,
Input,
Switch,
Rate,
Calendar,
ShortPassword,
Address
];
packages.forEach((item: any) => {
if (item.install) {
app.use(item);
} else if (item.name) {
app.component(item.name, item);
}
});
}
export default { install, version };

export {
Button,
Collapse,
Layout,
BackTop,
ActionSheet,
Toast,
Notify,
Picker,
Cell,
Uploader,
Icon,
Price,
Checkbox,
Swiper,
Avatar,
Popup,
Dialog,
Radio,
OverLay,
InfiniteLoading,
Range,
PullRefresh,
Navbar,
Tab,
Menu,
Tabbar,
InputNumber,
Input,
Switch,
Rate,
Calendar,
ShortPassword,
Address
};
export default { install, version: '3.0.0-beta.3' };
Loading

0 comments on commit 0f8b2ca

Please sign in to comment.