项目作者: ecomfe

项目描述 :
A Set of SAN UI Components that widely used on Baidu Cloud Console
高级语言: JavaScript
项目地址: git://github.com/ecomfe/san-xui.git
创建时间: 2018-01-19T03:34:19Z
项目社区:https://github.com/ecomfe/san-xui

开源协议:MIT License

下载


san-xui


Codecov
Dependency Status
npm package
NPM downloads
Percentage of issues still open

san-xui 是基于 san 开发的一套UI组件库,在百度云的控制台中得到了广泛的应用。

下载

NPM:

  1. npm i --save san-xui

使用

AMD

这里使用的是 esl 作为 AMD Loader,使用之前需要配置一下 paths 和 packages,如下:

  1. <script src="https://cdn.bdstatic.com/ecom/esl/2.2.0-rc.2/esl.js"></script>
  2. <script>
  3. require.config({
  4. paths: {
  5. san: "https://cdn.bdstatic.com/san/3.5.1-rc.1/san",
  6. jquery: "https://unpkg.com/jquery@3.3.1/dist/jquery",
  7. humanize: "https://unpkg.com/humanize@0.0.9/humanize",
  8. lodash: "https://unpkg.com/lodash@4.17.5/lodash",
  9. moment: "https://unpkg.com/moment@2.21.0/moment",
  10. axios: "https://unpkg.com/axios@0.18.0/dist/axios",
  11. clipboard: "https://unpkg.com/clipboard@2.0.0/dist/clipboard",
  12. "async-validator": "https://cdn.bdstatic.com/console/async-validator/0.0.0/async-validator.bundle",
  13. "big.js": "https://unpkg.com/big.js@5.0.3/big"
  14. },
  15. packages: [
  16. {
  17. name: "san-xui",
  18. location: "https://unpkg.com/san-xui@0.2.0/lib",
  19. main: "index"
  20. }
  21. ]
  22. });
  23. </script>

引入所需要的样式代码:

  1. <link rel="stylesheet" type="text/css" href="https://cdn.bdstatic.com/iconfont/iconfont.css" />
  2. <link rel="stylesheet" type="text/css" href="https://unpkg.com/san-xui@0.2.0/dist/xui.css" />

最后是应用的代码:

  1. define(function(require) {
  2. const san = require("san");
  3. const { Button, alert } = require("san-xui");
  4. const App = san.defineComponent({
  5. template: `<template><ui-button on-click="onBtnClick">Hello san-xui</ui-button></template>`,
  6. components: {
  7. "ui-button": Button
  8. },
  9. onBtnClick() {
  10. alert("Button clicked");
  11. }
  12. });
  13. function start() {
  14. const app = new App();
  15. app.attach(document.getElementById("root"));
  16. }
  17. return { start };
  18. });

最终的效果如下:https://codepen.io/leeight/pen/QmMabe

Webpack

通过 named import 导入所需要使用的组件

  1. import 'san-xui/dist/xui.css';
  2. import {defineComponent} from 'san';
  3. import {Button} from 'san-xui';
  4. // 引入单个的组件
  5. import Button from 'san-xui/lib/x/components/Button';
  6. const App = defineComponent({
  7. template: `<template><ui-button>Hello san-xui</ui-button></template>`,
  8. components: {
  9. 'ui-button': Button
  10. }
  11. });
  12. const app = new App();
  13. app.attach(document.body);

webpack.config.js

需要安装必要的一些插件

  1. npm i --save-dev babel-loader css-loader style-loader less-loader less file-loader babel-preset-stage-0 babel-preset-env

然后补充上一些相关的配置

  1. const path = require('path');
  2. function alias(name) {
  3. return path.dirname(require.resolve(name));
  4. }
  5. module.exports = {
  6. ...
  7. resolve: {
  8. mainFiles: ['index', 'main']
  9. },
  10. module: {
  11. rules: [
  12. {
  13. test: /\.(png|gif|jpe?g|svg)$/,
  14. use: [
  15. {
  16. loader: 'file-loader',
  17. options: {
  18. name(file) {
  19. return 'assets/images/[hash].[ext]';
  20. }
  21. }
  22. }
  23. ]
  24. },
  25. {
  26. test: /\.css$/,
  27. use: ['style-loader', 'css-loader']
  28. },
  29. {
  30. test: /\.less$/,
  31. use: [
  32. {loader: 'style-loader'},
  33. {loader: 'css-loader'},
  34. {
  35. loader: 'less-loader',
  36. options: {
  37. relativeUrls: true,
  38. paths: []
  39. }
  40. }
  41. ]
  42. },
  43. {
  44. test: /\.js$/,
  45. exclude: /(node_modules|dist)/,
  46. use: {
  47. loader: 'babel-loader',
  48. options: {
  49. presets: ['env', 'stage-0']
  50. }
  51. }
  52. }
  53. ]
  54. },
  55. ...
  56. }