├── .gitignore ├── .npmignore ├── .travis.yml ├── src ├── rules │ ├── jquery.ts │ ├── moment.ts │ ├── react-dom.ts │ ├── react.ts │ └── antd.ts ├── index.ts └── type.ts ├── README.md ├── tslint.json ├── tsconfig.json └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /lib 3 | /yarn.lock 4 | 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /src 2 | /test 3 | /node_modules 4 | tsconfig.json 5 | tslint.json 6 | .editorconfig 7 | .gitlab-ci.yml 8 | History.md 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "8" 4 | - "10" 5 | 6 | before_script: 7 | - npm run lint 8 | - npm run build 9 | 10 | cache: 11 | directories: 12 | - node_modules 13 | 14 | git: 15 | depth: 5 16 | -------------------------------------------------------------------------------- /src/rules/jquery.ts: -------------------------------------------------------------------------------- 1 | import { IConfigItem } from '../type'; 2 | 3 | const rules: IConfigItem = { 4 | key: 'jquery', 5 | global: 'jQuery', 6 | scripts: { 7 | development: ['dist/jquery.js'], 8 | production: ['dist/jquery.min.js'], 9 | }, 10 | }; 11 | 12 | export default rules; 13 | -------------------------------------------------------------------------------- /src/rules/moment.ts: -------------------------------------------------------------------------------- 1 | import { IConfigItem } from '../type'; 2 | 3 | const rules: IConfigItem = { 4 | key: 'moment', 5 | global: 'moment', 6 | scripts: { 7 | development: ['min/moment-with-locales.js'], 8 | production: ['min/moment-with-locales.min.js'], 9 | }, 10 | }; 11 | 12 | export default rules; 13 | -------------------------------------------------------------------------------- /src/rules/react-dom.ts: -------------------------------------------------------------------------------- 1 | import { IConfigItem } from '../type'; 2 | 3 | const rules: IConfigItem = { 4 | key: 'react-dom', 5 | global: 'ReactDOM', 6 | scripts: { 7 | development: ['umd/react-dom.development.js'], 8 | production: ['umd/react-dom.production.min.js'], 9 | }, 10 | dependencies: ['react'], 11 | }; 12 | 13 | export default rules; 14 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { readdirSync } from 'fs'; 2 | import { join } from 'path'; 3 | import { IConfigItem } from './type'; 4 | 5 | const ruleFiles = readdirSync(join(__dirname, 'rules')); 6 | const res: IConfigItem[] = []; 7 | ruleFiles.forEach((subPath) => { 8 | if (/\.d\.ts/.test(subPath)) { 9 | return; 10 | } 11 | const item = require(join(__dirname, 'rules', subPath)).default; 12 | res.push(item); 13 | }); 14 | 15 | export default res; 16 | -------------------------------------------------------------------------------- /src/type.ts: -------------------------------------------------------------------------------- 1 | interface IUrls { 2 | development: string[]; 3 | production: string[]; 4 | } 5 | 6 | export interface IConfigItem { 7 | key: string; // library name 8 | global?: string | ((context: string, request: string, callback: any) => any); 9 | 10 | scripts: IUrls; // js url 11 | styles?: IUrls; // style url 12 | polyfillUrls?: IUrls; 13 | 14 | polyfillExclude?: string[]; // polyfills 15 | dependencies?: string[]; // external 之间的依赖关系 16 | } 17 | -------------------------------------------------------------------------------- /src/rules/react.ts: -------------------------------------------------------------------------------- 1 | import { IConfigItem } from '../type'; 2 | 3 | const rules: IConfigItem = { 4 | key: 'react', 5 | global: 'React', 6 | scripts: { 7 | development: ['umd/react.development.js'], 8 | production: ['umd/react.production.min.js'], 9 | }, 10 | polyfillUrls: { 11 | development: ['umd/react.profiling.min.js'], 12 | production: ['umd/react.profiling.min.js'], 13 | }, 14 | polyfillExclude: ['core-js/es6/map', 'core-js/es6/set'], 15 | }; 16 | 17 | export default rules; 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # auto-external-packages 2 | 3 | External package configs. 4 | 5 | [![NPM version](https://img.shields.io/npm/v/auto-external-packages.svg?style=flat)](https://npmjs.org/package/auto-external-packages) 6 | [![Build Status](https://img.shields.io/travis/umijs/auto-external-packages.svg?style=flat)](https://travis-ci.org/umijs/auto-external-packages) 7 | [![NPM downloads](http://img.shields.io/npm/dm/auto-external-packages.svg?style=flat)](https://npmjs.org/package/auto-external-packages) 8 | 9 | ## Questions & Suggestions 10 | 11 | Please open an issue [here](https://github.com/umijs/umi/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc). 12 | 13 | ## LICENSE 14 | 15 | MIT 16 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "tslint:latest" 4 | ], 5 | "rules": { 6 | "no-empty": false, 7 | "quotemark": [ 8 | true, 9 | "single", 10 | "jsx-single" 11 | ], 12 | "ordered-imports": false, 13 | "member-access": false, 14 | "no-submodule-imports": false, 15 | "jsx-curly-spacing": [ 16 | "always" 17 | ], 18 | "no-console": false, 19 | "object-literal-sort-keys": false, 20 | "no-implicit-dependencies": false, 21 | "no-empty-interface": false, 22 | "trailing-comma": [ 23 | true, 24 | { 25 | "multiline": "always", 26 | "singleline": "never" 27 | } 28 | ] 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "typeRoots": [ 5 | "./node_modules/@types", 6 | "./global.d.ts" 7 | ], 8 | "target": "es5", 9 | "lib": ["es2015", "es2016", "es2017", "dom"], 10 | "module": "commonjs", 11 | "noImplicitAny": false, 12 | "outDir": "lib", 13 | "declaration": true, 14 | "experimentalDecorators": true, 15 | "emitDecoratorMetadata": true, 16 | "charset": "utf8", 17 | "allowJs": false, 18 | "pretty": true, 19 | "noEmitOnError": false, 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | "allowUnreachableCode": false, 23 | "allowUnusedLabels": false, 24 | "noFallthroughCasesInSwitch": true, 25 | "skipLibCheck": true, 26 | "skipDefaultLibCheck": true, 27 | "importHelpers": true 28 | }, 29 | "include": [ 30 | "src/**/*" 31 | ], 32 | "exclude": [ 33 | "node_modules" 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "auto-external-packages", 3 | "version": "1.0.0", 4 | "description": "external package configs", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "precommit": "npm run lint-staged", 8 | "lint-staged": "lint-staged", 9 | "prepublishOnly": "npm run build", 10 | "clean": "rimraf ./lib", 11 | "build": "npm run clean && tsc", 12 | "test": "", 13 | "lint": "tslint --project ./tsconfig.json", 14 | "lint:fix": "tslint --fix --project ./tsconfig.json" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git@github.com:umijs/auto-external-packages.git" 19 | }, 20 | "keywords": [ 21 | "client" 22 | ], 23 | "authors": [ 24 | "ikobe (https://github.com/ikobe)" 25 | ], 26 | "license": "MIT", 27 | "devDependencies": { 28 | "@types/node": "^10.12.1", 29 | "@types/uuid": "^3.4.4", 30 | "lint-staged": "^8.0.4", 31 | "rimraf": "^2.6.3", 32 | "tslint": "^5.11.0", 33 | "typescript": "^3.1.3" 34 | }, 35 | "lint-staged": { 36 | "linters": { 37 | "src/**/*.ts": "npm run lint" 38 | }, 39 | "ignore": [ 40 | "src/typings/**.ts" 41 | ] 42 | }, 43 | "dependencies": { 44 | "lodash": "^4.17.11" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/rules/antd.ts: -------------------------------------------------------------------------------- 1 | import { IConfigItem } from '../type'; 2 | import { upperFirst, camelCase } from 'lodash'; 3 | 4 | function upcaseAntdComponent(component: string) { 5 | if (['notification', 'message'].indexOf(component) > -1) { 6 | return component; 7 | } 8 | return upperFirst(camelCase(component)); 9 | } 10 | 11 | const rules: IConfigItem = { 12 | key: 'antd', 13 | scripts: { 14 | development: ['dist/antd-with-locales.js'], 15 | production: ['dist/antd-with-locales.min.js'], 16 | }, 17 | styles: { 18 | development: ['dist/antd.css'], 19 | production: ['dist/antd.min.css'], 20 | }, 21 | dependencies: ['react', 'react-dom', 'moment'], 22 | global: (_, request, callback) => { 23 | if ( 24 | !/antd/.test(request) || 25 | /style/.test(request) || 26 | /locale-provider\/.*/.test(request) 27 | ) { 28 | return callback(); 29 | } 30 | // @alipay/bigfish/antd/es/spin => antd/es/spin 31 | const antdRequest = (request || '').replace(/@alipay\/bigfish\//, ''); 32 | // 未使用 babel-plugin-import 33 | if (antdRequest === 'antd') { 34 | return callback(null, ['antd'], 'window'); 35 | } 36 | 37 | // 使用了 babel-plugin-import 38 | const [libraryName, , component] = antdRequest.split('/'); 39 | return callback( 40 | null, 41 | [libraryName, upcaseAntdComponent(component)], 42 | 'window', 43 | ); 44 | }, 45 | }; 46 | 47 | export default rules; 48 | --------------------------------------------------------------------------------