mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
build: update scripts
This commit is contained in:
parent
4e5318ba53
commit
53989cc4a3
5 changed files with 66 additions and 10 deletions
|
|
@ -5,7 +5,8 @@
|
|||
"dev": "node ./scripts/dev-vite.js",
|
||||
"dev:board": "node ./scripts/dev-rollup.js board",
|
||||
"build": "npm run build:src && npm run build:min",
|
||||
"build:src": "NODE_ENV=production BUILD_MODE=reset node ./scripts/build.js",
|
||||
"build:src": "NODE_ENV=production BUILD_MODE=reset node ./scripts/build-bundle.js",
|
||||
"build:mod": "node ./scripts/build-module.js",
|
||||
"build:min": "node ./scripts/minify.js",
|
||||
"snapshot": "node ./scripts/build.js && node ./scripts/snapshot.js",
|
||||
"e2e": "mocha --exit ./__tests__/e2e.test.js",
|
||||
|
|
@ -45,6 +46,7 @@
|
|||
"eslint": "^7.27.0",
|
||||
"execa": "^5.0.0",
|
||||
"fs-extra": "^9.1.0",
|
||||
"glob": "^7.2.0",
|
||||
"http-server": "^0.12.3",
|
||||
"husky": "^6.0.0",
|
||||
"jest": "^26.6.3",
|
||||
|
|
|
|||
52
scripts/build-module.js
Normal file
52
scripts/build-module.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
const ts = require('typescript');
|
||||
const babel = require('@babel/core');
|
||||
const glob = require("glob");
|
||||
const { packages } = require('./config');
|
||||
const { resolvePackagePath, getTsConfig } = require('./util/project');
|
||||
|
||||
build();
|
||||
|
||||
async function build() {
|
||||
packages.forEach(async (pkg) => {
|
||||
buildPackage(pkg.dirName);
|
||||
});
|
||||
}
|
||||
|
||||
function buildPackage(dirName) {
|
||||
const pattern = '**/*.ts';
|
||||
const cwd = resolvePackagePath(dirName, 'src');
|
||||
const files = glob.sync(pattern, { cwd, });
|
||||
|
||||
const targetFiles = files.map((file) => {
|
||||
return resolvePackagePath(dirName, 'src', file);
|
||||
});
|
||||
|
||||
// build ts -> esm
|
||||
{
|
||||
const tsConfig = getTsConfig();
|
||||
const compilerOptions = tsConfig.compilerOptions;
|
||||
compilerOptions.target = ts.ScriptTarget.ES2015;
|
||||
compilerOptions.moduleResolution = ts.ModuleResolutionKind.NodeJs;
|
||||
compilerOptions.declaration = true;
|
||||
compilerOptions.outDir = resolvePackagePath(dirName, 'dist', 'esm');
|
||||
compilerOptions.rootDir = resolvePackagePath(dirName, 'src');
|
||||
const program = ts.createProgram(targetFiles, compilerOptions);
|
||||
program.emit();
|
||||
}
|
||||
|
||||
// build ts -> cjs
|
||||
{
|
||||
const tsConfig = getTsConfig();
|
||||
const compilerOptions = tsConfig.compilerOptions;
|
||||
compilerOptions.target = ts.ScriptTarget.ES5;
|
||||
compilerOptions.moduleResolution = ts.ModuleResolutionKind.NodeJs;
|
||||
compilerOptions.declaration = true;
|
||||
compilerOptions.outDir = resolvePackagePath(dirName, 'dist', 'cjs');
|
||||
compilerOptions.rootDir = resolvePackagePath(dirName, 'src');
|
||||
const program = ts.createProgram(targetFiles, compilerOptions);
|
||||
program.emit();
|
||||
}
|
||||
|
||||
// console.log('files ===', files);
|
||||
}
|
||||
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
function resolvePackagePath() {
|
||||
const pathList = Array.from(arguments);
|
||||
|
|
@ -12,8 +13,16 @@ function resolveProjectPath() {
|
|||
return path.join(baseDir, ...pathList);
|
||||
}
|
||||
|
||||
function getTsConfig() {
|
||||
const configPath = resolveProjectPath('tsconfig.json')
|
||||
const configStr = fs.readFileSync(configPath, { encoding: 'utf8' });
|
||||
const config = JSON.parse(configStr);
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
resolveProjectPath,
|
||||
resolvePackagePath,
|
||||
getTsConfig,
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
"sourceMap": false,
|
||||
"target": "es5",
|
||||
"module": "ES2015",
|
||||
|
|
@ -14,18 +12,13 @@
|
|||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true,
|
||||
"removeComments": true,
|
||||
"jsx": "preserve",
|
||||
"lib": ["ESNext", "dom"],
|
||||
"rootDir": ".",
|
||||
// "paths": {
|
||||
// "idraw": ["packages/idraw/src1"]
|
||||
// }
|
||||
"lib": ["ESNext", "dom"]
|
||||
},
|
||||
"include": [
|
||||
"packages/global.d.ts",
|
||||
"packages/*/src",
|
||||
"packages/*/__tests__",
|
||||
"packages/*/dev",
|
||||
"packages/*/dev"
|
||||
],
|
||||
"exclude": [
|
||||
"packages/*/examples"
|
||||
|
|
|
|||
Loading…
Reference in a new issue