mirror of
https://gitee.com/openharmony/third_party_jsframework
synced 2024-11-22 22:30:12 +00:00
Optimize build js
Issue:https://gitee.com/openharmony/third_party_jsframework/issues/I5NJ0I Signed-off-by: yinchuang <yinchuang@huawei.com>
This commit is contained in:
parent
e8bac1d334
commit
98cdd784df
9
BUILD.gn
9
BUILD.gn
@ -58,7 +58,8 @@ action("gen_snapshot") {
|
||||
}
|
||||
}
|
||||
|
||||
buildfile = "//third_party/jsframework/build.js"
|
||||
buildfile_jsmock = "//third_party/jsframework/build_jsmock_system_plugin.js"
|
||||
buildfile_native_min = "//third_party/jsframework/build_strip_native_min.js"
|
||||
|
||||
package_file = "//third_party/jsframework/package.json"
|
||||
tsconfig = "//third_party/jsframework/tsconfig.json"
|
||||
@ -67,7 +68,7 @@ action("gen_snapshot") {
|
||||
test_file = "//third_party/jsframework/test"
|
||||
|
||||
args = [
|
||||
rebase_path(buildfile, root_build_dir),
|
||||
rebase_path(buildfile_jsmock, root_build_dir),
|
||||
rebase_path(nodejs_path, root_build_dir),
|
||||
rebase_path(js_framework, root_build_dir),
|
||||
rebase_path(node_modules, root_build_dir),
|
||||
@ -79,6 +80,7 @@ action("gen_snapshot") {
|
||||
rebase_path(babel, root_build_dir),
|
||||
is_mac,
|
||||
rebase_path("//prebuilts", root_build_dir),
|
||||
rebase_path(buildfile_native_min, root_build_dir),
|
||||
]
|
||||
|
||||
inputs = [
|
||||
@ -172,7 +174,8 @@ action("gen_snapshot") {
|
||||
# config of compiler
|
||||
".babelrc",
|
||||
".eslintrc",
|
||||
"build.js",
|
||||
"build_jsmock_system_plugin.js",
|
||||
"build_strip_native_min.js",
|
||||
"tsconfig.json",
|
||||
"tslint.json",
|
||||
]
|
||||
|
@ -11,7 +11,7 @@
|
||||
- `test/ut/`:unit test file
|
||||
- `.eslintrc`:eslint configure
|
||||
- `BUILD.gn`:compiling file of JS UI framework for NinjaJS
|
||||
- `build.js`:build JS framework
|
||||
- `build_jsmock_system_plugin.js, build_strip_native_min.js`: build JS framework
|
||||
- `js_framework_build.sh`:script file for JS framework building
|
||||
- `LICENSE`:Apache License
|
||||
- `NOTICE`:third party open source software notice
|
||||
@ -35,7 +35,7 @@ Please make sure that the following commands work before trying to build:
|
||||
Your `npm` and `node` should be of a later version. You can upgrade them to the **latest stable version**.
|
||||
### 2. Installing
|
||||
|
||||
RollUp tool for packaging has been configured in `build.js`. So after the preceding conditions are met, we can start installing right now.
|
||||
RollUp tool for packaging has been configured in `build_jsmock_system_plugin.js, build_strip_native_min.js`. So after the preceding conditions are met, we can start installing right now.
|
||||
|
||||
First, we go to the root directory of the project:
|
||||
```
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -57,22 +57,6 @@ const esPlugin = eslint({
|
||||
exclude: ['node_modules/**', 'lib/**']
|
||||
});
|
||||
|
||||
const configInput = {
|
||||
input: path.resolve(__dirname, 'runtime/preparation/index.ts'),
|
||||
onwarn,
|
||||
plugins: [
|
||||
esPlugin,
|
||||
tsPlugin,
|
||||
json(),
|
||||
resolve(),
|
||||
commonjs(),
|
||||
babel({
|
||||
exclude: 'node_moduels/**'
|
||||
}),
|
||||
uglify()
|
||||
]
|
||||
};
|
||||
|
||||
const configJSAPIMockInput = {
|
||||
input: path.resolve(__dirname, 'runtime/main/extend/systemplugin/entry.js'),
|
||||
onwarn,
|
||||
@ -88,24 +72,12 @@ const configJSAPIMockInput = {
|
||||
]
|
||||
};
|
||||
|
||||
const configOutput = {
|
||||
file: path.resolve(__dirname, 'dist/strip.native.min.js'),
|
||||
format: 'umd',
|
||||
banner: frameworkBanner
|
||||
};
|
||||
|
||||
const configJSAPIMockOutput = {
|
||||
file: path.resolve(__dirname, 'dist/jsMockSystemPlugin.js'),
|
||||
format: 'umd',
|
||||
banner: frameworkBannerForJSAPIMock
|
||||
};
|
||||
|
||||
rollup.rollup(configInput).then(bundle => {
|
||||
bundle.write(configOutput).then(() => {
|
||||
countSize(configOutput.file);
|
||||
});
|
||||
});
|
||||
|
||||
rollup.rollup(configJSAPIMockInput).then(bundle => {
|
||||
bundle.write(configJSAPIMockOutput).then(() => {
|
||||
countSize(configJSAPIMockOutput.file);
|
||||
@ -114,7 +86,7 @@ rollup.rollup(configJSAPIMockInput).then(bundle => {
|
||||
|
||||
function countSize(filePath) {
|
||||
const file = path.relative(__dirname, filePath);
|
||||
fs.stat(filePath, function(error, stats) {
|
||||
fs.stat(filePath, function (error, stats) {
|
||||
if (error) {
|
||||
console.error('file size is wrong');
|
||||
} else {
|
99
build_strip_native_min.js
Normal file
99
build_strip_native_min.js
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const path = require('path');
|
||||
|
||||
const rollup = require('rollup');
|
||||
|
||||
const resolve = require('rollup-plugin-node-resolve');
|
||||
|
||||
const commonjs = require('rollup-plugin-commonjs');
|
||||
|
||||
const json = require('rollup-plugin-json');
|
||||
|
||||
const babel = require('rollup-plugin-babel');
|
||||
|
||||
const typescript = require('rollup-plugin-typescript2');
|
||||
|
||||
const { uglify } = require('rollup-plugin-uglify');
|
||||
|
||||
const {
|
||||
eslint
|
||||
} = require('rollup-plugin-eslint');
|
||||
|
||||
const frameworkBanner = `var global=this; var process={env:{}}; ` + `var setTimeout=global.setTimeout;\n`;
|
||||
|
||||
const frameworkBannerForJSAPIMock = `var global=globalThis;`;
|
||||
|
||||
const onwarn = warning => {
|
||||
// Silence circular dependency warning
|
||||
if (warning.code === 'CIRCULAR_DEPENDENCY') {
|
||||
return;
|
||||
}
|
||||
console.warn(`(!) ${warning.message}`);
|
||||
};
|
||||
|
||||
const tsPlugin = typescript({
|
||||
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
|
||||
check: true
|
||||
});
|
||||
|
||||
const esPlugin = eslint({
|
||||
include: ['**/*.ts'],
|
||||
exclude: ['node_modules/**', 'lib/**']
|
||||
});
|
||||
|
||||
const configInput = {
|
||||
input: path.resolve(__dirname, 'runtime/preparation/index.ts'),
|
||||
onwarn,
|
||||
plugins: [
|
||||
esPlugin,
|
||||
tsPlugin,
|
||||
json(),
|
||||
resolve(),
|
||||
commonjs(),
|
||||
babel({
|
||||
exclude: 'node_moduels/**'
|
||||
}),
|
||||
uglify()
|
||||
]
|
||||
};
|
||||
|
||||
const configOutput = {
|
||||
file: path.resolve(__dirname, 'dist/strip.native.min.js'),
|
||||
format: 'umd',
|
||||
banner: frameworkBanner
|
||||
};
|
||||
|
||||
rollup.rollup(configInput).then(bundle => {
|
||||
bundle.write(configOutput).then(() => {
|
||||
countSize(configOutput.file);
|
||||
});
|
||||
});
|
||||
|
||||
function countSize(filePath) {
|
||||
const file = path.relative(__dirname, filePath);
|
||||
fs.stat(filePath, function (error, stats) {
|
||||
if (error) {
|
||||
console.error('file size is wrong');
|
||||
} else {
|
||||
const size = (stats.size / 1024).toFixed(2) + 'KB';
|
||||
console.log(`generate snapshot file: ${file}...\nthe snapshot file size: ${size}...`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ cp -f $6 $9
|
||||
cp -f $7 $9
|
||||
cp -f ${10} $9
|
||||
cp -f $1 $9
|
||||
cp -f ${13} $9
|
||||
cp -r $8 $9
|
||||
|
||||
if [ -d "$prebuilts_path" ]; then
|
||||
echo "prebuilts exists"
|
||||
# address problme of parallzing compile
|
||||
@ -49,13 +49,17 @@ if [ -d "$prebuilts_path" ]; then
|
||||
cp -r $2 $9
|
||||
cd $9
|
||||
if [ "${11}" == 'true' ];then
|
||||
./node-v12.18.4-darwin-x64/bin/node build.js
|
||||
./node-v12.18.4-darwin-x64/bin/node build_jsmock_system_plugin.js || exit 1 &
|
||||
./node-v12.18.4-darwin-x64/bin/node build_strip_native_min.js || exit 1 &
|
||||
# run unit test
|
||||
./node-v12.18.4-darwin-x64/bin/node node_modules/.bin/mocha -r ts-node/register test/lib.ts test/ut/**/*.ts test/ut/*.ts
|
||||
./node-v12.18.4-darwin-x64/bin/node node_modules/.bin/mocha -r ts-node/register test/lib.ts test/ut/**/*.ts test/ut/*.ts || exit 1 &
|
||||
wait
|
||||
else
|
||||
./node-v12.18.4-linux-x64/bin/node build.js
|
||||
./node-v12.18.4-linux-x64/bin/node build_jsmock_system_plugin.js || exit 1 &
|
||||
./node-v12.18.4-linux-x64/bin/node build_strip_native_min.js || exit 1 &
|
||||
# run unit test
|
||||
./node-v12.18.4-linux-x64/bin/node node_modules/.bin/mocha -r ts-node/register test/lib.ts test/ut/**/*.ts test/ut/*.ts
|
||||
./node-v12.18.4-linux-x64/bin/node node_modules/.bin/mocha -r ts-node/register test/lib.ts test/ut/**/*.ts test/ut/*.ts || exit 1&
|
||||
wait
|
||||
fi
|
||||
else
|
||||
npm run build
|
||||
@ -72,7 +76,8 @@ else
|
||||
fi
|
||||
rm -rf ./runtime
|
||||
rm -rf ./tsconfig.json
|
||||
rm -rf ./build.js
|
||||
rm -rf build_jsmock_system_plugin.js
|
||||
rm -rf build_strip_native_min.js
|
||||
rm -rf ./test
|
||||
rm -rf ./.eslintrc
|
||||
rm -rf ./.babelrc
|
||||
|
@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"test:lint": "eslint -c .eslintrc --fix test/**/*.ts",
|
||||
"test:unit": "mocha --timeout 5000 -r ts-node/register test/lib.ts test/ut/**/*.ts test/ut/*.ts",
|
||||
"build": "node build.js"
|
||||
"build": "node build_jsmock_system_plugin.js && node build_strip_native_min.js"
|
||||
},
|
||||
"keywords": [
|
||||
"javascript",
|
||||
|
Loading…
Reference in New Issue
Block a user