Skip to content

Commit

Permalink
chore(lerna): clean latest
Browse files Browse the repository at this point in the history
  • Loading branch information
deot committed Jun 20, 2020
1 parent e92ecd9 commit 746cf4c
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 88 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

```
# 避免权限问题,这样安装
sudo npm install -g --unsafe-perm --verbose @wya/doc
sudo npm install -g --unsafe-perm --verbose @wya/doc-cli
```

- 跟随项目

```
npm install @wya/doc -D
npm install @wya/doc-cli -D
```

### TODO
Expand Down
41 changes: 30 additions & 11 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
const APP_ROOT = process.cwd();
const path = require('path');

module.exports = (api) => {
// 编译缓存
api && api.cache.forever();
api.cache.forever();

return {
presets: ['@babel/preset-env'],
presets: [
["@babel/preset-env"]
],
plugins: [
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-function-bind",
"@babel/plugin-syntax-dynamic-import",
// node-resolve中modulesOnly为true, 否者会存在无用代码
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
"@babel/plugin-transform-runtime", {
"corejs": false,
"helpers": true,
"regenerator": true,
"useESModules": false
}
],
"@babel/plugin-transform-runtime"

]
],
// "@babel/plugin-external-helpers",
["@babel/plugin-proposal-decorators", { legacy: true }],
["@babel/plugin-proposal-class-properties", { loose: true }],
"transform-vue-jsx"
],
env: {
"test": {
"plugins": ["istanbul"]
}
}
};
};
};
21 changes: 14 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,23 @@
"@babel/core": "^7.10.2",
"@babel/helper-module-imports": "^7.10.1",
"@babel/plugin-proposal-class-properties": "^7.10.1",
"@babel/plugin-transform-regenerator": "^7.10.1",
"@babel/plugin-proposal-decorators": "^7.10.1",
"@babel/plugin-proposal-export-default-from": "^7.10.1",
"@babel/plugin-proposal-export-namespace-from": "^7.10.1",
"@babel/plugin-proposal-function-bind": "^7.10.1",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-jsx": "^7.10.1",
"@babel/plugin-transform-runtime": "^7.10.1",
"@babel/preset-env": "^7.10.1",
"@babel/runtime": "^7.10.2",
"@rollup/plugin-buble": "^0.21.1",
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-replace": "^2.3.1",
"@rollup/plugin-babel": "^5.0.3",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-commonjs": "^13.0.0",
"@rollup/plugin-node-resolve": "^8.0.1",
"@rollup/plugin-replace": "^2.3.3",
"babel-eslint": "^10.0.3",
"babel-plugin-istanbul": "^6.0.0",
"babel-plugin-transform-vue-jsx": "^4.0.1",
"cross-env": "^7.0.0",
"cssnano": "^4.1.10",
"eslint": "^6.8.0",
Expand All @@ -63,8 +71,7 @@
"postcss-preset-env": "^6.7.0",
"postcss-simple-vars": "^5.0.2",
"regenerator-runtime": "0.11.1",
"rollup": "^2.1.0",
"rollup-plugin-babel": "^4.3.3",
"rollup": "^2.17.1",
"rollup-plugin-postcss": "^3.1.1",
"rollup-plugin-uglify": "^6.0.4",
"rollup-plugin-vue": "^5.0.1",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@babel/plugin-proposal-function-bind": "^7.10.1",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-jsx": "^7.10.1",
"@babel/plugin-transform-runtime": "^7.10.1",
"@babel/plugin-transform-modules-commonjs": "^7.10.1",
"@babel/preset-env": "^7.10.2",
"@babel/runtime": "^7.10.2",
Expand Down
31 changes: 19 additions & 12 deletions packages/cli/src/node/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
const { resolve } = path;
const cwd = process.cwd();

const resolvePackage = (source) => {
let nms = [
resolve(__dirname, '../node_modules', source),
resolve(cwd, './node_modules', source),
resolve(cwd, '../../node_modules', source),
...module.paths.map($path => resolve($path, source))
];
const BASIC_NMS = [
resolve(__dirname, '../node_modules'),
resolve(cwd, './node_modules'),
resolve(cwd, '../../node_modules')
];
const NMS = [
...BASIC_NMS,
// 增加编译速度
...module.paths
];

let fullpath = nms.find(i => fs.pathExistsSync(i));
const resolvePackage = (source) => {
let $path = NMS.find(i => fs.pathExistsSync(resolve(i, source)));

if (!fullpath) {
if (!$path) {
throw new Error(`@wya/doc: 未找到${source}`);
}

return fullpath;
return resolve($path, source);
};
const resolveClient = (source) => {
return resolve(__dirname, '../client', source || '');
Expand Down Expand Up @@ -58,7 +62,7 @@ class Config {
) {
__DEP_VC__ = true;
}
const exclude = new RegExp(resolve(__dirname, '../node_modules'));
const exclude = new RegExp(`(${BASIC_NMS.join('|')})`);

// 不允许被覆盖的配置
const noOverrideConfig = {
Expand All @@ -77,7 +81,7 @@ class Config {
},
resolve: {
modules: [
...module.paths,
...BASIC_NMS,
process.cwd()
],
extensions: ['.vue', '.js', '.json', '.md', '.css', '.scss'],
Expand All @@ -91,6 +95,8 @@ class Config {
'@utils': resolveClient('src/utils'),
'@client': resolveClient(),
'@app': resolveClient(),
'@wya/doc-utils': resolvePackage('@wya/doc-utils/src/index.js'),
'@wya/doc-playground': resolvePackage('@wya/doc-playground/src/index.js'),
}
},
module: {
Expand All @@ -115,6 +121,7 @@ class Config {
resolvePackage('@babel/plugin-syntax-dynamic-import'),
resolvePackage('@babel/plugin-transform-modules-commonjs'),
resolvePackage('@babel/plugin-syntax-jsx'),
resolvePackage("@babel/plugin-transform-runtime"),
resolvePackage('babel-plugin-transform-vue-jsx'),
[
resolvePackage('@babel/plugin-proposal-decorators'),
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/src/node/helper/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ module.exports = ({ port, host, server }) => {
wss.on('connection', (socket, request) => {
socketArr.push(socket);

console.log(`[event connection] - 连接数:${socketArr.length}`);
// 服务端订阅
socket.on('message', (res) => {
console.log('log:', res);
});

socket.on('close', (res) => {
socketArr = socketArr.filter(i => i != socket && i.readyState == 1);

console.log(`[event close] - 连接数:${socketArr.length}`);
});

socket.on('error', (res) => {
socket.close();

console.log(`[event error]`, res);
});
});

Expand Down
38 changes: 0 additions & 38 deletions packages/playground/babel.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@wya/doc-playground",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"main": "dist/playground.min.js",
"files": [
"dist/**",
"src/**"
Expand Down
4 changes: 3 additions & 1 deletion packages/playground/src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = require('./playground.vue');
import Playground from './playground.vue';

export default Playground;
2 changes: 1 addition & 1 deletion packages/playground/src/playground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import Vue from 'vue';
import { Clipboard } from '@wya/vc';
import { Compiler, Load } from '@wya/doc-utils';
import { Editor } from './popup/editor';
import { Editor } from './popup/editor.vue';
const COPY = {
'zh-CN': "复制",
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/src/popup/editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import 'codemirror/mode/javascript/javascript.js';
import 'codemirror/addon/selection/active-line.js';
import 'codemirror/theme/material.css';
import 'codemirror/lib/codemirror.css';
import { Portal, Transition } from '@wya/vc';
import Portal from '@wya/vc/lib/portal';
import Transition from '@wya/vc/lib/transition';
import { Drag } from '@wya/doc-utils';
const wrapperComponent = {
Expand Down
5 changes: 3 additions & 2 deletions packages/playground/tests/webpack.config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const postcssLoader = {
loader: resolvePackage('postcss-loader'),
options: {
config: {
path: resolve(__dirname, '../postcss.config.js')
path: resolve(__dirname, '../../../postcss.config.js')
}
}
};
Expand All @@ -47,7 +47,8 @@ module.exports = {
{
loader: resolvePackage('babel-loader'),
options: {
cacheDirectory: true // 启用编译缓存
cacheDirectory: true,
extends: resolve(__dirname, '../../../babel.config.js')
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@wya/doc-utils",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"main": "dist/utils.min.js",
"files": [
"dist/**",
"src/**"
Expand Down
File renamed without changes.
28 changes: 17 additions & 11 deletions scripts/config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('path');
const { babel } = require('@rollup/plugin-babel');
const buble = require('@rollup/plugin-buble');
const replace = require('@rollup/plugin-replace');
const commonjs = require('@rollup/plugin-commonjs');
const nodeResolve = require('@rollup/plugin-node-resolve');
const babel = require('rollup-plugin-babel');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const { uglify } = require('rollup-plugin-uglify');
const postcss = require('rollup-plugin-postcss');
const vue = require('rollup-plugin-vue');
Expand All @@ -18,9 +18,15 @@ const external = filename => {
let regex = [
'^vue$',
'^@babel/runtime',
// 用于测试用例?

'^@wya/ps$',
'^@wya/utils$'
'^@wya/utils$',
'^@wya/vc',

'^markdown-it$',
'^markdown-it-chain$',
'^markdown-it-container$',
'^codemirror'
].join('|');

return new RegExp(`(${regex})`).test(filename);
Expand Down Expand Up @@ -63,16 +69,17 @@ const builds = {
],
extensions: ['.css', '.scss'],
})
]
],
external
},
external,
},
utils: {
script: 'babel packages/utils/src --out-dir packages/utils/dist --copy-files --ignore **.test.js,**.md,examples/**',
rollup: {
entry: 'packages/utils/src/index.js',
dest: 'packages/utils/dist/utils.min.js',
format: 'cjs'
format: 'cjs',
external
}
}
};
Expand Down Expand Up @@ -101,7 +108,7 @@ class Config {
}),
// 使用cjs模块引入
commonjs({
include: /node_modules/
include: 'node_modules/**'
}),
replace({
'__DEV__': 'false',
Expand All @@ -110,12 +117,11 @@ class Config {
}),
...(opts.plugins || []),
babel({
babelrc: true,
exclude: 'node_modules/**',
runtimeHelpers: true
babelHelpers: 'runtime'
}),
buble({
objectAssign: 'Object.assign' // ...Object spread and rest
objectAssign: 'Object.assign'
})
// process.env.NODE_ENV === 'production' && uglify()
],
Expand Down

0 comments on commit 746cf4c

Please sign in to comment.