@boxfoxs/scraping-bundler 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +3 -0
- package/bin/build.sh +27 -0
- package/dist/index.js +14 -0
- package/package.json +72 -0
- package/src/index.ts +1 -0
- package/src/util/readJsonFile.ts +6 -0
- package/src/util/shell.ts +9 -0
- package/src/webpack/options/devServer.ts +31 -0
- package/src/webpack/options/environments.ts +1 -0
- package/src/webpack/options/optimization.ts +20 -0
- package/src/webpack/options/rules.ts +38 -0
- package/src/webpack/tsconfig-for-webpack-config.json +7 -0
- package/src/webpack/utils/getLocalhostAddresses.ts +9 -0
- package/src/webpack/utils/parseAlias.ts +16 -0
- package/src/webpack/webpack.base.config.ts +94 -0
- package/tsconfig.json +21 -0
package/.eslintrc.json
ADDED
package/bin/build.sh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
|
|
3
|
+
print_usage_and_exit() {
|
|
4
|
+
printf "\$ 정확한 빌드 타입을 선택해주세요 (dev | prod | hot | analyze)\n"
|
|
5
|
+
exit 1
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
init_tsconfig() {
|
|
9
|
+
SCRIPT_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
|
10
|
+
TSCONFIG_PATH="$SCRIPT_PATH/../dist/webpack/tsconfig-for-webpack-config.json"
|
|
11
|
+
yarn cross-env TS_NODE_PROJECT=\"$TSCONFIG_PATH\"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
run_script() {
|
|
15
|
+
export BUILD_MODE=${2:-prod}
|
|
16
|
+
init_tsconfig
|
|
17
|
+
|
|
18
|
+
if [[ $BUILD_MODE == dev* ]] || [[ $BUILD_MODE == prod* ]] || [[ $BUILD_MODE == analyze* ]]; then
|
|
19
|
+
yarn webpack --config $1
|
|
20
|
+
elif [[ $BUILD_MODE == hot* ]]; then
|
|
21
|
+
yarn webpack-dev-server --config $1 --watch
|
|
22
|
+
else
|
|
23
|
+
print_usage_and_exit
|
|
24
|
+
fi
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
run_script "$@"
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./webpack/webpack.base.config"), exports);
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@boxfoxs/scraping-bundler",
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"description": "",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/esm/",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"scripts": {
|
|
10
|
+
"clean": "rm -rf dist && mkdir dist",
|
|
11
|
+
"build": "tsc -p tsconfig.json",
|
|
12
|
+
"fix": "sts fix",
|
|
13
|
+
"deploy": "yarn build && yarn publish --access=public"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"scraping-build": "bin/build.sh"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^13.11.1",
|
|
20
|
+
"barreler": "^0.0.5",
|
|
21
|
+
"typescript": "^3.9.3"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@babel/cli": "^7.11.6",
|
|
25
|
+
"@babel/core": "^7.11.6",
|
|
26
|
+
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
|
27
|
+
"@babel/plugin-proposal-decorators": "^7.10.5",
|
|
28
|
+
"@babel/plugin-proposal-optional-catch-binding": "^7.10.4",
|
|
29
|
+
"@babel/plugin-transform-async-to-generator": "^7.10.4",
|
|
30
|
+
"@babel/plugin-transform-regenerator": "^7.10.4",
|
|
31
|
+
"@babel/plugin-transform-runtime": "^7.11.5",
|
|
32
|
+
"@babel/plugin-transform-typescript": "^7.11.0",
|
|
33
|
+
"@babel/preset-env": "^7.11.5",
|
|
34
|
+
"@babel/runtime-corejs3": "^7.11.2",
|
|
35
|
+
"@types/clean-webpack-plugin": "^0.1.3",
|
|
36
|
+
"@types/fs-extra": "^9.0.1",
|
|
37
|
+
"@types/lodash": "^4.14.161",
|
|
38
|
+
"@types/morgan": "^1.9.1",
|
|
39
|
+
"@types/node": "^14.0.27",
|
|
40
|
+
"@types/node-fetch": "^2.5.7",
|
|
41
|
+
"@types/nodegit": "^0.26.8",
|
|
42
|
+
"@types/shelljs": "^0.8.8",
|
|
43
|
+
"@types/terser-webpack-plugin": "^4.2.0",
|
|
44
|
+
"@types/webpack-bundle-analyzer": "^3.8.0",
|
|
45
|
+
"@types/webpack-dev-server": "^3.11.0",
|
|
46
|
+
"@types/webpack-merge": "^4.1.5",
|
|
47
|
+
"@types/webpackbar": "^4.0.0",
|
|
48
|
+
"babel-loader": "^8.1.0",
|
|
49
|
+
"babel-plugin-module-resolver": "^4.0.0",
|
|
50
|
+
"circular-dependency-plugin": "^4.4.0",
|
|
51
|
+
"clean-webpack-plugin": "^3.0.0",
|
|
52
|
+
"cross-env": "^7.0.2",
|
|
53
|
+
"fs-extra": "^9.0.1",
|
|
54
|
+
"helmet": "^4.1.1",
|
|
55
|
+
"lodash": "^4.17.20",
|
|
56
|
+
"morgan": "^1.10.0",
|
|
57
|
+
"node-fetch": "^2.6.1",
|
|
58
|
+
"s3-deploy": "^1.4.0",
|
|
59
|
+
"script-loader": "^0.7.2",
|
|
60
|
+
"shelljs": "^0.8.4",
|
|
61
|
+
"terser-webpack-plugin": "^4.2.1",
|
|
62
|
+
"ts-node": "^9.0.0",
|
|
63
|
+
"tsconfig-paths": "^3.9.0",
|
|
64
|
+
"typescript": "^3.9.7",
|
|
65
|
+
"webpack": "^4.44.1",
|
|
66
|
+
"webpack-bundle-analyzer": "^3.8.0",
|
|
67
|
+
"webpack-cli": "^3.3.12",
|
|
68
|
+
"webpack-dev-server": "^3.11.0",
|
|
69
|
+
"webpack-merge": "^5.1.4",
|
|
70
|
+
"webpackbar": "^4.0.0"
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './webpack/webpack.base.config';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import helmet from 'helmet';
|
|
2
|
+
import morgan from 'morgan';
|
|
3
|
+
import { Configuration } from 'webpack-dev-server';
|
|
4
|
+
import { getLocalhostAddresses } from '../utils/getLocalhostAddresses';
|
|
5
|
+
|
|
6
|
+
const localhostNames = getLocalhostAddresses();
|
|
7
|
+
|
|
8
|
+
export function createDevServerOption(staticPath: string): Configuration {
|
|
9
|
+
return {
|
|
10
|
+
allowedHosts: localhostNames,
|
|
11
|
+
|
|
12
|
+
before: app => {
|
|
13
|
+
app.use(helmet({ hsts: false }));
|
|
14
|
+
app.use(morgan('dev'));
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
after: () => {
|
|
18
|
+
console.log('\n\nAvailable on:');
|
|
19
|
+
console.log(`${localhostNames.map(hostname => ` http://${hostname}:10808`).join('\n')}\n`);
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
hot: false,
|
|
23
|
+
inline: false,
|
|
24
|
+
contentBase: staticPath,
|
|
25
|
+
disableHostCheck: true,
|
|
26
|
+
host: '0.0.0.0',
|
|
27
|
+
port: 10808,
|
|
28
|
+
writeToDisk: true,
|
|
29
|
+
quiet: true,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const BUILD_MODE = process.env.BUILD_MODE;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import TerserPlugin from 'terser-webpack-plugin';
|
|
2
|
+
|
|
3
|
+
export const optimizationOption = {
|
|
4
|
+
usedExports: true,
|
|
5
|
+
minimizer: [
|
|
6
|
+
new TerserPlugin({
|
|
7
|
+
cache: true,
|
|
8
|
+
parallel: true,
|
|
9
|
+
sourceMap: true,
|
|
10
|
+
terserOptions: {
|
|
11
|
+
warnings: false,
|
|
12
|
+
compress: { ecma: 6, dead_code: false, passes: 3 },
|
|
13
|
+
mangle: { safari10: true },
|
|
14
|
+
keep_classnames: true,
|
|
15
|
+
output: { ecma: 6, beautify: false, safari10: true, comments: false },
|
|
16
|
+
},
|
|
17
|
+
extractComments: false,
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { RuleSetRule } from 'webpack';
|
|
2
|
+
|
|
3
|
+
export function createDefaultRules(sourcePath: string): RuleSetRule[] {
|
|
4
|
+
const transpileRule = {
|
|
5
|
+
test: /\.(js|ts|jsx|tsx)$/,
|
|
6
|
+
include: sourcePath,
|
|
7
|
+
exclude: [/node_modules/, /.*preload\.js/],
|
|
8
|
+
use: {
|
|
9
|
+
loader: 'babel-loader',
|
|
10
|
+
options: {
|
|
11
|
+
presets: [
|
|
12
|
+
['@babel/preset-env', { exclude: ['@babel/plugin-transform-async-to-generator'] }],
|
|
13
|
+
],
|
|
14
|
+
plugins: [
|
|
15
|
+
['@babel/plugin-transform-typescript', { allowNamespaces: true, isTSX: true }],
|
|
16
|
+
['@babel/plugin-transform-regenerator', {}],
|
|
17
|
+
['@babel/plugin-proposal-decorators', { legacy: true }],
|
|
18
|
+
['@babel/plugin-proposal-class-properties', {}],
|
|
19
|
+
['@babel/plugin-proposal-optional-catch-binding', {}],
|
|
20
|
+
['@babel/plugin-transform-runtime', { corejs: { version: 3, proposals: true } }],
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const preloadRule = {
|
|
27
|
+
test: /\.preload\.js$/,
|
|
28
|
+
use: [
|
|
29
|
+
{
|
|
30
|
+
loader: 'script-loader',
|
|
31
|
+
options: {
|
|
32
|
+
sourceMap: false,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
return [transpileRule, preloadRule];
|
|
38
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { flatMap } from 'lodash';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
|
|
4
|
+
export function getLocalhostAddresses(): string[] {
|
|
5
|
+
const candidates = flatMap(Object.values(os.networkInterfaces()));
|
|
6
|
+
return candidates
|
|
7
|
+
.filter(item => item != null && item.family === 'IPv4')
|
|
8
|
+
.map(item => item!.address);
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { readJsonFile } from '../../util/readJsonFile';
|
|
3
|
+
|
|
4
|
+
interface TypescriptConfig {
|
|
5
|
+
compilerOptions: {
|
|
6
|
+
paths?: Record<string, string[]>;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function parseAlias(tsConfigPath: string, sourcePath: string): Record<string, string> {
|
|
11
|
+
const tsConfig: TypescriptConfig = readJsonFile(tsConfigPath);
|
|
12
|
+
return Object.entries(tsConfig.compilerOptions.paths ?? {})
|
|
13
|
+
.map(([alias, targetPaths]) => [alias.replace('/*', ''), targetPaths[0].replace('/*', '')])
|
|
14
|
+
.map(([key, value]) => [key, path.resolve(sourcePath, value)])
|
|
15
|
+
.reduce((acc, [key, val]) => ({ ...acc, [key]: val }), {});
|
|
16
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Webpack modules.
|
|
2
|
+
import { CleanWebpackPlugin } from "clean-webpack-plugin";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { Configuration, DefinePlugin } from "webpack";
|
|
5
|
+
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
|
|
6
|
+
import webpackMerge from "webpack-merge";
|
|
7
|
+
import ProgressBarPlugin from "webpackbar";
|
|
8
|
+
import { readJsonFile } from "../util/readJsonFile";
|
|
9
|
+
import { createDevServerOption } from "./options/devServer";
|
|
10
|
+
import { BUILD_MODE } from "./options/environments";
|
|
11
|
+
import { optimizationOption } from "./options/optimization";
|
|
12
|
+
import { createDefaultRules } from "./options/rules";
|
|
13
|
+
import { parseAlias } from "./utils/parseAlias";
|
|
14
|
+
//@ts-ignore
|
|
15
|
+
import CircularDependencyPlugin from "circular-dependency-plugin";
|
|
16
|
+
|
|
17
|
+
const configuration: Configuration = {
|
|
18
|
+
performance: { hints: false },
|
|
19
|
+
output: { filename: `[name].min.js` },
|
|
20
|
+
plugins: [
|
|
21
|
+
new CleanWebpackPlugin(),
|
|
22
|
+
new CircularDependencyPlugin({
|
|
23
|
+
exclude: /a\.js|node_modules/,
|
|
24
|
+
failOnError: true,
|
|
25
|
+
allowAsyncCycles: false,
|
|
26
|
+
cwd: process.cwd(),
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
29
|
+
resolve: {
|
|
30
|
+
extensions: [".js", ".ts", ".json"],
|
|
31
|
+
},
|
|
32
|
+
stats: "errors-warnings",
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function createWatchConfiguration(staticPath: string) {
|
|
36
|
+
return webpackMerge(configuration, {
|
|
37
|
+
devtool: "inline-source-map",
|
|
38
|
+
devServer: createDevServerOption(staticPath),
|
|
39
|
+
watchOptions: { ignored: /node_modules/, poll: true },
|
|
40
|
+
watch: true,
|
|
41
|
+
stats: "errors-only",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type WebpackConfigOfService = {
|
|
46
|
+
path: string;
|
|
47
|
+
tsconfig?: string;
|
|
48
|
+
webpack: Partial<Configuration>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function paresPackageInfo(porjectPath: string) {
|
|
52
|
+
const { name, version, targetName } = readJsonFile(
|
|
53
|
+
path.resolve(porjectPath, "package.json")
|
|
54
|
+
);
|
|
55
|
+
const tmpName: string = targetName ?? name;
|
|
56
|
+
const pureName = tmpName.substr(tmpName.lastIndexOf("/") + 1);
|
|
57
|
+
return { version, name: pureName };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function webpack(config: WebpackConfigOfService): Configuration {
|
|
61
|
+
const isProductionMode = ["analyze", "prod"].includes(BUILD_MODE ?? "");
|
|
62
|
+
const isHotMode = BUILD_MODE === "hot";
|
|
63
|
+
const isAnalyzeMode = BUILD_MODE === "analyze";
|
|
64
|
+
|
|
65
|
+
const { version, name } = paresPackageInfo(config.path);
|
|
66
|
+
const tsConfigPath =
|
|
67
|
+
config.tsconfig ?? path.resolve(config.path, "tsconfig.json");
|
|
68
|
+
const sourcePath = path.resolve(config.path, "src");
|
|
69
|
+
const outputPath = path.resolve(config.path, "dist");
|
|
70
|
+
const alias = parseAlias(tsConfigPath, config.path);
|
|
71
|
+
const analyzePlugins = isAnalyzeMode ? [new BundleAnalyzerPlugin()] : [];
|
|
72
|
+
|
|
73
|
+
const baseConfiguration = isHotMode
|
|
74
|
+
? createWatchConfiguration(outputPath)
|
|
75
|
+
: configuration;
|
|
76
|
+
const additionalConfigs = webpackMerge(config.webpack, {
|
|
77
|
+
mode: isProductionMode ? "production" : "development",
|
|
78
|
+
resolve: { alias },
|
|
79
|
+
entry: config.webpack.entry || { [name]: `${sourcePath}/index.ts` },
|
|
80
|
+
output: { path: outputPath },
|
|
81
|
+
module: { rules: createDefaultRules(sourcePath) },
|
|
82
|
+
plugins: [
|
|
83
|
+
new ProgressBarPlugin({ name }),
|
|
84
|
+
...analyzePlugins,
|
|
85
|
+
new DefinePlugin({
|
|
86
|
+
CA_DEBUG: !isProductionMode,
|
|
87
|
+
CA_VERSION: JSON.stringify(version),
|
|
88
|
+
CA_PRODUCTION: isProductionMode,
|
|
89
|
+
}),
|
|
90
|
+
],
|
|
91
|
+
optimization: isProductionMode ? optimizationOption : undefined,
|
|
92
|
+
});
|
|
93
|
+
return webpackMerge(baseConfiguration, additionalConfigs);
|
|
94
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es6",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"module": "commonjs",
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"noEmit": false,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"allowJs": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"noImplicitAny": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"baseUrl": ".",
|
|
17
|
+
"experimentalDecorators": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["src"],
|
|
20
|
+
"exclude": ["**/__mocks__/*", "**/__tests__/*", "**/__test__/*"]
|
|
21
|
+
}
|