Match-id-2fc345ba57e5fceee4ce6a1a05ce844445e3ed8d
This commit is contained in:
commit
3335e1f9c1
14
package.json
14
package.json
|
@ -5,7 +5,7 @@
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint . --ext .ts",
|
"lint": "eslint . --ext .ts",
|
||||||
"build": " webpack --config ./scripts/webpack/webpack.config.js",
|
"build": " rollup --config ./scripts/rollup/rollup.config.js",
|
||||||
"build-3rdLib": "node ./scripts/gen3rdLib.js",
|
"build-3rdLib": "node ./scripts/gen3rdLib.js",
|
||||||
"build-3rdLib-dev": "npm run build & node ./scripts/gen3rdLib.js --dev",
|
"build-3rdLib-dev": "npm run build & node ./scripts/gen3rdLib.js --dev",
|
||||||
"build-horizon3rdLib-dev": "npm run build & node ./scripts/gen3rdLib.js --dev --type horizon",
|
"build-horizon3rdLib-dev": "npm run build & node ./scripts/gen3rdLib.js --dev --type horizon",
|
||||||
|
@ -51,6 +51,9 @@
|
||||||
"@babel/register": "^7.14.5",
|
"@babel/register": "^7.14.5",
|
||||||
"@babel/traverse": "^7.11.0",
|
"@babel/traverse": "^7.11.0",
|
||||||
"@mattiasbuelens/web-streams-polyfill": "^0.3.2",
|
"@mattiasbuelens/web-streams-polyfill": "^0.3.2",
|
||||||
|
"@rollup/plugin-babel": "^5.3.1",
|
||||||
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
||||||
|
"@rollup/plugin-replace": "^4.0.0",
|
||||||
"@types/jest": "^26.0.24",
|
"@types/jest": "^26.0.24",
|
||||||
"@types/node": "^17.0.18",
|
"@types/node": "^17.0.18",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
||||||
|
@ -58,13 +61,11 @@
|
||||||
"babel-core": "^6.26.3",
|
"babel-core": "^6.26.3",
|
||||||
"babel-eslint": "^10.0.3",
|
"babel-eslint": "^10.0.3",
|
||||||
"babel-jest": "^27.5.1",
|
"babel-jest": "^27.5.1",
|
||||||
"babel-loader": "^8.2.2",
|
|
||||||
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
|
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
|
||||||
"babel-preset-env": "^1.7.0",
|
"babel-preset-env": "^1.7.0",
|
||||||
"babel-preset-react": "^6.24.1",
|
"babel-preset-react": "^6.24.1",
|
||||||
"chalk": "^3.0.0",
|
"chalk": "^3.0.0",
|
||||||
"confusing-browser-globals": "^1.0.9",
|
"confusing-browser-globals": "^1.0.9",
|
||||||
"copy-webpack-plugin": "5.0.4",
|
|
||||||
"core-js": "^3.6.4",
|
"core-js": "^3.6.4",
|
||||||
"danger": "^9.2.10",
|
"danger": "^9.2.10",
|
||||||
"ejs": "^3.1.6",
|
"ejs": "^3.1.6",
|
||||||
|
@ -77,7 +78,6 @@
|
||||||
"eslint-plugin-no-for-of-loops": "^1.0.0",
|
"eslint-plugin-no-for-of-loops": "^1.0.0",
|
||||||
"eslint-plugin-no-function-declare-after-return": "^1.0.0",
|
"eslint-plugin-no-function-declare-after-return": "^1.0.0",
|
||||||
"eslint-plugin-react": "^6.7.1",
|
"eslint-plugin-react": "^6.7.1",
|
||||||
"eslint-webpack-plugin": "^3.0.1",
|
|
||||||
"jest": "^25.5.4",
|
"jest": "^25.5.4",
|
||||||
"jest-cli": "^25.2.7",
|
"jest-cli": "^25.2.7",
|
||||||
"jest-diff": "^25.2.6",
|
"jest-diff": "^25.2.6",
|
||||||
|
@ -90,9 +90,9 @@
|
||||||
"react-lifecycles-compat": "^3.0.4",
|
"react-lifecycles-compat": "^3.0.4",
|
||||||
"regenerator-runtime": "^0.13.9",
|
"regenerator-runtime": "^0.13.9",
|
||||||
"rimraf": "^3.0.0",
|
"rimraf": "^3.0.0",
|
||||||
"typescript": "^3.9.7",
|
"rollup": "^2.75.5",
|
||||||
"webpack": "^4.46.0",
|
"rollup-plugin-terser": "^7.0.2",
|
||||||
"webpack-cli": "^4.7.2"
|
"typescript": "^3.9.7"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.x",
|
"node": ">=10.x",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
'use strict'
|
'use strict';
|
||||||
const ejs = require('ejs');
|
const ejs = require('ejs');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
@ -10,25 +10,30 @@ const argv = require('minimist')(process.argv.slice(2));
|
||||||
const libPathPrefix = '../build';
|
const libPathPrefix = '../build';
|
||||||
const suffix = argv.dev ? 'development.js' : 'production.js';
|
const suffix = argv.dev ? 'development.js' : 'production.js';
|
||||||
const template = argv.type === 'horizon' ? 'horizon3rdTemplate.ejs' : 'template.ejs';
|
const template = argv.type === 'horizon' ? 'horizon3rdTemplate.ejs' : 'template.ejs';
|
||||||
const readLib = (lib) => {
|
const readLib = lib => {
|
||||||
const libName = lib.split('.')[0];
|
const libName = lib.split('.')[0];
|
||||||
const libPath = path.resolve(__dirname, `${libPathPrefix}/${libName}/umd/${lib}`);
|
const libPath = path.resolve(__dirname, `${libPathPrefix}/${libName}/umd/${lib}`);
|
||||||
if (fs.existsSync(libPath)) {
|
if (fs.existsSync(libPath)) {
|
||||||
return fs.readFileSync(libPath,'utf-8');
|
return fs.readFileSync(libPath, 'utf-8');
|
||||||
} else {
|
} else {
|
||||||
console.log(chalk.red(`Error: "${libPath}" 文件不存在\n先运行 npm run build`))
|
console.log(chalk.red(`Error: "${libPath}" 文件不存在\n先运行 npm run build`));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ejs.renderFile(path.resolve(__dirname, `./${template}`), {
|
ejs.renderFile(
|
||||||
Horizon: readLib(`horizon.${suffix}`),
|
path.resolve(__dirname, `./${template}`),
|
||||||
}, null, function(err, result) {
|
{
|
||||||
const common3rdLibPath = path.resolve(__dirname, `${libPathPrefix}/horizonCommon3rdlib.min.js`)
|
Horizon: readLib(`horizon.${suffix}`),
|
||||||
rimRaf(common3rdLibPath, e => {
|
},
|
||||||
if (e) {
|
null,
|
||||||
console.log(e)
|
function(err, result) {
|
||||||
}
|
const common3rdLibPath = path.resolve(__dirname, `${libPathPrefix}/horizonCommon3rdlib.min.js`);
|
||||||
fs.writeFileSync(common3rdLibPath, result);
|
rimRaf(common3rdLibPath, e => {
|
||||||
console.log(chalk.green(`成功生成: ${common3rdLibPath}`))
|
if (e) {
|
||||||
})
|
console.log(e);
|
||||||
});
|
}
|
||||||
|
fs.writeFileSync(common3rdLibPath, result);
|
||||||
|
console.log(chalk.green(`成功生成: ${common3rdLibPath}`));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
|
export default function copyFiles(copyPairs) {
|
||||||
|
return {
|
||||||
|
name: 'copy-files',
|
||||||
|
generateBundle() {
|
||||||
|
copyPairs.forEach(({ from, to }) => {
|
||||||
|
console.log(`copy files: ${from} → ${to}`);
|
||||||
|
fs.copyFileSync(from, to);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
||||||
|
import babel from '@rollup/plugin-babel';
|
||||||
|
import path from 'path';
|
||||||
|
import replace from '@rollup/plugin-replace';
|
||||||
|
import copy from './copy-plugin';
|
||||||
|
import { terser } from 'rollup-plugin-terser';
|
||||||
|
import { version as horizonVersion } from '@cloudsop/horizon/package.json';
|
||||||
|
|
||||||
|
const extensions = ['.js', '.ts'];
|
||||||
|
|
||||||
|
const libDir = path.join(__dirname, '../../libs/horizon');
|
||||||
|
const rootDir = path.join(__dirname, '../..');
|
||||||
|
const outDir = path.join(rootDir, 'build', 'horizon');
|
||||||
|
const outputResolve = (...p) => path.resolve(outDir, ...p);
|
||||||
|
|
||||||
|
function genConfig(mode) {
|
||||||
|
const sourcemap = mode === 'development' ? 'inline' : false;
|
||||||
|
return {
|
||||||
|
input: path.resolve(libDir, 'index.ts'),
|
||||||
|
output: [
|
||||||
|
{
|
||||||
|
file: outputResolve('cjs', `horizon.${mode}.js`),
|
||||||
|
sourcemap,
|
||||||
|
format: 'cjs',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: outputResolve('umd', `horizon.${mode}.js`),
|
||||||
|
sourcemap,
|
||||||
|
name: 'Horizon',
|
||||||
|
format: 'umd',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
nodeResolve({
|
||||||
|
extensions,
|
||||||
|
modulesOnly: true,
|
||||||
|
}),
|
||||||
|
babel({
|
||||||
|
exclude: 'node_modules/**',
|
||||||
|
configFile: path.join(__dirname, '../../babel.config.js'),
|
||||||
|
babelHelpers: 'runtime',
|
||||||
|
extensions,
|
||||||
|
}),
|
||||||
|
replace({
|
||||||
|
values: {
|
||||||
|
'process.env.NODE_ENV': `"${mode}"`,
|
||||||
|
isDev: 'true',
|
||||||
|
__VERSION__: `"${horizonVersion}"`,
|
||||||
|
},
|
||||||
|
preventAssignment: true,
|
||||||
|
}),
|
||||||
|
mode === 'production' && terser(),
|
||||||
|
copy([
|
||||||
|
{
|
||||||
|
from: path.join(libDir, 'index.js'),
|
||||||
|
to: path.join(outDir, 'index.js'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: path.join(libDir, 'package.json'),
|
||||||
|
to: path.join(outDir, 'package.json'),
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default [genConfig('development'), genConfig('production')];
|
|
@ -1,28 +0,0 @@
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const libPath = path.join(__dirname, '../../libs/horizon');
|
|
||||||
const baseConfig = {
|
|
||||||
entry: path.resolve(libPath, 'index.ts'),
|
|
||||||
module: {
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
test: /\.(js)|ts$/,
|
|
||||||
exclude: /node_modules/,
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
loader: 'babel-loader'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
extensions: ['.js', '.ts'],
|
|
||||||
alias: {
|
|
||||||
'horizon-external': path.join(libPath, './horizon-external'),
|
|
||||||
'horizon': path.join(libPath, './horizon'),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = baseConfig;
|
|
|
@ -1,4 +0,0 @@
|
||||||
const dev = require('./webpack.dev');
|
|
||||||
const pro = require('./webpack.pro');
|
|
||||||
|
|
||||||
module.exports = [...dev, ...pro];
|
|
|
@ -1,45 +0,0 @@
|
||||||
const webpack = require('webpack');
|
|
||||||
const ESLintPlugin = require('eslint-webpack-plugin');
|
|
||||||
const baseConfig = require('./webpack.base');
|
|
||||||
const path = require('path');
|
|
||||||
const horizonVersion = require('../../libs/horizon/package.json').version;
|
|
||||||
|
|
||||||
const mode = 'development';
|
|
||||||
const devtool = 'inline-source-map';
|
|
||||||
const filename = 'horizon.development.js';
|
|
||||||
|
|
||||||
const plugins = [
|
|
||||||
new ESLintPlugin({fix: true}),
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
'process.env.NODE_ENV': '"development"',
|
|
||||||
isDev: 'true',
|
|
||||||
__VERSION__: `"${horizonVersion}"`,
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
|
|
||||||
const umd = {
|
|
||||||
...baseConfig,
|
|
||||||
mode,
|
|
||||||
devtool,
|
|
||||||
output: {
|
|
||||||
path: path.resolve(__dirname, '../../build/horizon/umd'),
|
|
||||||
filename,
|
|
||||||
libraryTarget: 'umd',
|
|
||||||
library: 'Horizon',
|
|
||||||
},
|
|
||||||
plugins,
|
|
||||||
};
|
|
||||||
|
|
||||||
const cjs = {
|
|
||||||
...baseConfig,
|
|
||||||
mode,
|
|
||||||
devtool,
|
|
||||||
output: {
|
|
||||||
path: path.resolve(__dirname, '../../build/horizon/cjs'),
|
|
||||||
filename,
|
|
||||||
libraryTarget: 'commonjs',
|
|
||||||
},
|
|
||||||
plugins,
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = [umd, cjs];
|
|
|
@ -1,61 +0,0 @@
|
||||||
const webpack = require('webpack');
|
|
||||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
||||||
const baseConfig = require('./webpack.base');
|
|
||||||
const path = require('path');
|
|
||||||
const horizonVersion = require('../../libs/horizon/package.json').version;
|
|
||||||
|
|
||||||
const mode = 'production';
|
|
||||||
const devtool = 'none';
|
|
||||||
const filename = 'horizon.production.js';
|
|
||||||
|
|
||||||
const plugins = [
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
'process.env.NODE_ENV': '"production"',
|
|
||||||
isDev: 'false',
|
|
||||||
__VERSION__: `"${horizonVersion}"`,
|
|
||||||
})
|
|
||||||
];
|
|
||||||
|
|
||||||
const proBaseConfig = {
|
|
||||||
...baseConfig,
|
|
||||||
mode,
|
|
||||||
devtool,
|
|
||||||
plugins,
|
|
||||||
optimization: {
|
|
||||||
minimize: true
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const umd = {
|
|
||||||
...proBaseConfig,
|
|
||||||
output: {
|
|
||||||
path: path.resolve(__dirname, '../../build/horizon/umd'),
|
|
||||||
filename,
|
|
||||||
libraryTarget: 'umd',
|
|
||||||
library: 'Horizon',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const cjs = {
|
|
||||||
...proBaseConfig,
|
|
||||||
output: {
|
|
||||||
path: path.resolve(__dirname, '../../build/horizon/cjs'),
|
|
||||||
filename,
|
|
||||||
libraryTarget: 'commonjs',
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
...plugins,
|
|
||||||
new CopyWebpackPlugin([
|
|
||||||
{
|
|
||||||
from: path.join(__dirname, '../../libs/horizon/index.js'),
|
|
||||||
to: path.join(__dirname, '../../build/horizon/index.js'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
from: path.join(__dirname, '../../libs/horizon/package.json'),
|
|
||||||
to: path.join(__dirname, '../../build/horizon/package.json'),
|
|
||||||
}
|
|
||||||
])
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = [umd, cjs];
|
|
Loading…
Reference in New Issue