Skip to content

Commit

Permalink
build: 更改 rollup plugin 的导入方式
Browse files Browse the repository at this point in the history
  • Loading branch information
KonghaYao committed Aug 9, 2021
1 parent 5f55c77 commit 10f6533
Show file tree
Hide file tree
Showing 12 changed files with 72,544 additions and 494 deletions.
18,133 changes: 18,066 additions & 67 deletions dist/JSpider.cjs.min.js

Large diffs are not rendered by default.

18,131 changes: 18,064 additions & 67 deletions dist/JSpider.esm.min.js

Large diffs are not rendered by default.

18,235 changes: 18,119 additions & 116 deletions dist/JSpider.min.js

Large diffs are not rendered by default.

18,238 changes: 18,122 additions & 116 deletions dist/JSpider.umd.min.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"rollup-plugin-license": "^2.4.0",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-serve": "^1.1.0",
"rollup-plugin-terser": "^7.0.2",
"standard-version": "^9.3.0"
}
}
65 changes: 0 additions & 65 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 4 additions & 32 deletions rollup.config.build.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
import resolve from '@rollup/plugin-node-resolve'; // 帮助寻找node_modules里的包
import commonjs from '@rollup/plugin-commonjs'; // 将非ES6语法的包转为ES6可用
import { terser } from 'rollup-plugin-terser';
import license from 'rollup-plugin-license';
import del from 'rollup-plugin-delete';
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import CONFIG from './package.json';
import alias from '@rollup/plugin-alias';
import defaultPlugin from './script/rollup.plugins.js';
const plugins = [
alias({
entries: {
'@tools': './package/tools',
'@src': './src',
'@plugins': './package/plugins',
'@FakeServer': './package/FakeServer',
},
}),
replace({
preventAssignment: true,
values: {
__version__: JSON.stringify(CONFIG.version),
__buildDate__: new Date().getTime(),
'process.env.NODE_ENV': JSON.stringify('production'),
},
}),
json(),
resolve({
jsnext: true,
browser: true,
}),
commonjs(), // 将 CommonJS 转换成 ES2015 模块供 Rollup 处理

terser(),
del({ targets: 'dist/*' }),
...defaultPlugin,
license({
banner: {
content: {
Expand All @@ -43,7 +15,7 @@ const plugins = [
export default [
{
input: 'index.js', // 通用版本打包
plugins: [del({ targets: 'dist/*' }), ...plugins],
plugins,
output: [
{
// 打包出口
Expand Down
32 changes: 2 additions & 30 deletions rollup.config.dev.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import resolve from '@rollup/plugin-node-resolve'; // 帮助寻找node_modules里的包
import commonjs from '@rollup/plugin-commonjs'; // 将非ES6语法的包转为ES6可用
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import CONFIG from './package.json';
import livereload from 'rollup-plugin-livereload';
import serve from 'rollup-plugin-serve';
import alias from '@rollup/plugin-alias';

import defaultPlugin from './script/rollup.plugins.js';
export default {
input: 'index.js', // 打包入口
output: [
Expand All @@ -23,29 +17,7 @@ export default {
},
],
plugins: [
alias({
entries: {
'@tools': './package/tools',
'@src': './src',
'@plugins': './package/plugins',
'@FakeServer': './package/FakeServer',
},
}),
replace({
preventAssignment: true,
values: {
__version__: JSON.stringify(CONFIG.version),
__buildDate__: new Date().getTime(),
'process.env.NODE_ENV': JSON.stringify('production'),
},
}),
json(),
resolve({
jsnext: true,
browser: true,
}),
commonjs(), // 将 CommonJS 转换成 ES2015 模块供 Rollup 处理

...defaultPlugin,
livereload({ watch: 'dist' }),
serve({
openPage: '/test.html',
Expand Down
31 changes: 31 additions & 0 deletions script/rollup.plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import resolve from '@rollup/plugin-node-resolve'; // 帮助寻找node_modules里的包
import commonjs from '@rollup/plugin-commonjs'; // 将非ES6语法的包转为ES6可用
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import CONFIG from '../package.json';
import alias from '@rollup/plugin-alias';

export default [
alias({
entries: {
'@tools': './package/tools',
'@src': './src',
'@plugins': './package/plugins',
'@FakeServer': './package/FakeServer',
},
}),
replace({
preventAssignment: true,
values: {
__version__: JSON.stringify(CONFIG.version),
__buildDate__: new Date().getTime(),
'process.env.NODE_ENV': JSON.stringify('production'),
},
}),
json(),
resolve({
jsnext: true,
browser: true,
}),
commonjs(), // 将 CommonJS 转换成 ES2015 模块供 Rollup 处理
];
1 change: 1 addition & 0 deletions test/text-bilibili.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import('https://cdn.jsdelivr.net/npm/js-spider@3.2.3/dist/JSpider.esm.min.js').t
let spider = new JSpider()
.pipeline(
Request({
delay: 300,
buffer: 1,
}),
Combine(50, 1000, (dataArray) => {
Expand Down
69 changes: 69 additions & 0 deletions test/text-douyin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import('https://cdn.jsdelivr.net/npm/js-spider@3.2.3/dist/JSpider.esm.min.js').then(async (res) => {
let JSpider = res.default;
let {
Plugin,
plugins: { ExcelHelper, Request, Download, ZipFile, Combine },
} = JSpider;
await JSpider.$load('xlsx');
await JSpider.$load('lodash');
await JSpider.$load('jszip');
let keyword = encodeURI('奥运');

let number = 36 || 744;
const aid = '671cc434-cded-4123-aad8-be48a9b5a62e';
const searchID = '2021080820531701021203523228D85563';
let urls = [...Array(Math.ceil(number / 12)).keys()].map((i) => {
return {
url: `https://www.douyin.com/aweme/v1/web/search/item/?device_platform=webapp&aid=6383&channel=channel_pc_web&search_channel=aweme_video_web&sort_type=0&publish_time=0&keyword=${keyword}&search_source=normal_search&query_correct_type=1&is_filter_search=0&offset=${
i * 12
}&count=12&search_id=${searchID}&version_code=160100&version_name=16.1.0&cookie_enabled=true&screen_width=1536&screen_height=864&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0+(Windows+NT+10.0%3B+Win64%3B+x64)+AppleWebKit%2F537.36+(KHTML,+like+Gecko)+Chrome%2F92.0.4515.131+Safari%2F537.36+Edg%2F92.0.902.67&browser_online=true`,
options: {
headers: {
accept: 'application/json, text/plain, */*',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'cache-control': 'no-cache',
pragma: 'no-cache',
'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Microsoft Edge";v="92"',
'sec-ch-ua-mobile': '?0',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
withcredentials: 'true',
},
referrer: `https://www.douyin.com/search/${keyword}?source=normal_search&aid=${aid}&enter_from=main_page`,
credentials: 'include',
},
};
});
let spider = new JSpider()
.pipeline(
Request({
delay: 1000,
buffer: 1,
}),
Combine(50, 3000, (dataArray) => {
debugger;
return dataArray
.map((i) => {
return i.data
.map((item) => item['aweme_info'])
.map((item) => {
return {
author: item.author.nickname,
count: item.statistics.digg_count,
createTime: new Date(Number(item['create_time'] + '000')).toLocaleDateString(),
};
});
})
.flat()
.flat();
}),
ExcelHelper((dataset) => {
debugger;
return { a: dataset };
}),
Download(),
)
.crawl(urls)
.start();
});
Loading

0 comments on commit 10f6533

Please sign in to comment.