diff options
author | miripiruni <miripiruni@yandex-team.ru> | 2022-06-10 19:30:01 +0300 |
---|---|---|
committer | miripiruni <miripiruni@yandex-team.ru> | 2022-06-10 19:30:01 +0300 |
commit | 2c43eefa708ca732b77975f88db06d9110b8d9e6 (patch) | |
tree | 426c99699f264e9ab2afaf82ce3673522af893d2 /build | |
parent | 3f8e49145135cc23222b75eadc38c623ce5dc5e1 (diff) | |
download | ydb-2c43eefa708ca732b77975f88db06d9110b8d9e6.tar.gz |
feat: webpack bundling support
```bash
$ exa -la ~/arc2/arcadia/devtools/dummy_arcadia/ts/packages/with_simple_bundling
.rw-rw-r-- 240 miripiruni 2 Jun 17:10 package.json
.rw-rw-r-- 671 miripiruni 31 May 16:27 pnpm-lock.yaml
drwxrwxr-x - miripiruni 31 May 15:04 src
.rw-rw-r-- 654 miripiruni 31 May 15:04 tsconfig.json
.rw-rw-r-- 2.0k miripiruni 1 Jun 19:59 webpack.config.js
.rw-rw-r-- 74 miripiruni 2 Jun 16:43 ya.make
```
```bash
$ arc checkout users/miripiruni/FEI-24499_webpack
$ cd devtools/ymake
$ ya make
$ cd /home/miripiruni/arc2/arcadia/devtools/dummy_arcadia/ts/packages/with_simple_bundling
$ ya make --ymake-bin=/home/miripiruni/arc2/arcadia/devtools/ymake/bin/ymake
```
```bash
$ exa -la ~/arc2/arcadia/devtools/dummy_arcadia/ts/packages/with_simple_bundling
lrwxrwxr-x 77 miripiruni 2 Jun 16:36 bundle.tar -> /home/miripiruni/.ya/build/symres/5a9b0624d6972cef0ae58390036dd09b/bundle.tar
.rw-rw-r-- 240 miripiruni 2 Jun 17:10 package.json
.rw-rw-r-- 671 miripiruni 31 May 16:27 pnpm-lock.yaml
drwxrwxr-x - miripiruni 31 May 15:04 src
.rw-rw-r-- 654 miripiruni 31 May 15:04 tsconfig.json
.rw-rw-r-- 2.0k miripiruni 1 Jun 19:59 webpack.config.js
.rw-rw-r-- 74 miripiruni 2 Jun 16:43 ya.make
$ vim bundle.tar
" tar.vim version v29
" Browsing tarfile /home/miripiruni/arc2/arcadia/devtools/dummy_arcadia/ts/packages/with_simple_bundling/bundle.tar
" Select a file with cursor and press ENTER
home/miripiruni/.ya/build/build_root/o428/000005/devtools/dummy_arcadia/ts/packages/with_simple_bundling/bundle/
home/miripiruni/.ya/build/build_root/o428/000005/devtools/dummy_arcadia/ts/packages/with_simple_bundling/bundle/bundle.js
~
```
A: https://st.yandex-team.ru/FEI-24499#629756e217f92d2ead87669c
ref:c51f7008cdcd23f7dccae3e830cae7a5dc127d1b
Diffstat (limited to 'build')
-rw-r--r-- | build/conf/ts.conf | 34 | ||||
-rw-r--r-- | build/external_resources/webpack/generate-webpack-resource.sh | 36 | ||||
-rw-r--r-- | build/external_resources/webpack/readme.md | 11 |
3 files changed, 80 insertions, 1 deletions
diff --git a/build/conf/ts.conf b/build/conf/ts.conf index 8fc221c3ca..58766b3198 100644 --- a/build/conf/ts.conf +++ b/build/conf/ts.conf @@ -4,6 +4,8 @@ PNPM_ROOT=$PNPM_RESOURCE_GLOBAL PNPM_SCRIPT=$PNPM_ROOT/pnpm.js TSC_ROOT=$TS_COMPILER_RESOURCE_GLOBAL/typescript TSC_SCRIPT=$TSC_ROOT/lib/tsc.js +WEBPACK_ROOT=$WEBPACK_RESOURCE_GLOBAL/node_modules +WEBPACK_SCRIPT=$WEBPACK_ROOT/.bin/webpack NOTS_TOOL=${tool:"tools/nots"} NOTS_TOOL_BASE_ARGS=--build-root $ARCADIA_BUILD_ROOT --bindir $BINDIR --curdir $CURDIR --nodejs-bin $NODEJS_BIN @@ -79,7 +81,7 @@ module _TS_BASE_UNIT: _BASE_UNIT { TS_CONFIG_PATH=tsconfig.json -TS_COMPILE=${cwd:BINDIR} $NOTS_TOOL compile-ts $NOTS_TOOL_BASE_ARGS --tsc-script $TSC_SCRIPT --config ${input:TS_CONFIG_PATH} $_NODE_MODULES_INPUTS ${output;hide:"package.json"} ${kv;hide:"p FE"} ${kv;hide:"pc yellow"} && $TOUCH_UNIT +TS_COMPILE=${cwd:BINDIR} $NOTS_TOOL compile-ts $NOTS_TOOL_BASE_ARGS --tsc-script $TSC_SCRIPT --config ${input:TS_CONFIG_PATH} ${hide:PEERS} $_NODE_MODULES_INPUTS ${output;hide:"package.json"} ${kv;hide:"p FE"} ${kv;hide:"pc yellow"} && $TOUCH_UNIT ### @usage: TS_LIBRARY([name]) ### @@ -100,6 +102,36 @@ module TS_LIBRARY : _TS_BASE_UNIT { .PEERDIR_POLICY=as_build_from SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${CURDIR}/${TS_CONFIG_PATH} ${CURDIR}/package.json) + SET(TS_CONFIG_DEDUCE_OUT yes) + + _TS_CONFIGURE($TS_CONFIG_PATH) +} + +WEBPACK_CONFIG_PATH=webpack.config.js + +TS_BUNDLE_WEBPACK=${cwd:BINDIR} $NOTS_TOOL bundle-webpack $NOTS_TOOL_BASE_ARGS --webpack-root $WEBPACK_ROOT --webpack-script $WEBPACK_SCRIPT --config ${input:WEBPACK_CONFIG_PATH} ${hide:PEERS} $_NODE_MODULES_INPUTS ${output;hide:"bundle.tar"} ${kv;hide:"p FE"} ${kv;hide:"pc yellow"} && $TOUCH_UNIT + +### @usage: TS_BUNDLE([name]) +### +### The Webpack bundle, bundles JavaScript code. +### Build results are bundle.tar, typings and source mappings (depending on local tsconfig.json settings). +### +### @see [NODE_MODULES()](#macro_NODE_MODULES) +### @example +### +### TS_BUNDLE() +### SRCS(src/index.ts) +### NODE_MODULES() +### END() +### +module TS_BUNDLE : _TS_BASE_UNIT { + .CMD=TS_BUNDLE_WEBPACK + .FINAL_TARGET=yes + .PEERDIR_POLICY=as_build_from + + DECLARE_EXTERNAL_RESOURCE(WEBPACK sbr:2815569512) + SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${CURDIR}/${WEBPACK_CONFIG_PATH} ${CURDIR}/package.json) + SET(TS_CONFIG_DEDUCE_OUT no) _TS_CONFIGURE($TS_CONFIG_PATH) } diff --git a/build/external_resources/webpack/generate-webpack-resource.sh b/build/external_resources/webpack/generate-webpack-resource.sh new file mode 100644 index 0000000000..cba20981f3 --- /dev/null +++ b/build/external_resources/webpack/generate-webpack-resource.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -e + +WEBPACK_VERSION="5.69.1" +PACKAGES="webpack@$WEBPACK_VERSION webpack-cli@4.9.2 ts-loader@9.2.6 typescript@4.5.5" + +cd ~ + +TMP_DIR="tmp" +if [[ ! -d $TMP_DIR ]] +then + mkdir $TMP_DIR +fi +cd $TMP_DIR + +WEBPACK_DIR="webpack-resource" +mkdir $WEBPACK_DIR && cd $WEBPACK_DIR + +npm init -y + +npm install --save-dev --save-exact --registry=https://npm.yandex-team.ru ${PACKAGES} +echo "Packages installed successfully" + +RESOURCE_DIR="node_modules" +ARCHIVE="webpack-$WEBPACK_VERSION.tar.gz" +tar --create --gzip --file=$ARCHIVE $RESOURCE_DIR +echo "Created file $(pwd)/$ARCHIVE" + +DESCR="Bundle for https://st.yandex-team.ru/FEI-24499. Content: ${PACKAGES}" +ya upload $ARCHIVE -d="${DESCR}" --ttl="inf" --attr="webpack=${WEBPACK_VERSION}" +echo "$ARCHIVE uploaded successfully" + +echo "Cleanup…" +rm -fr ~/tmp/$WEBPACK_DIR + +echo "Done." diff --git a/build/external_resources/webpack/readme.md b/build/external_resources/webpack/readme.md new file mode 100644 index 0000000000..9b60f41e89 --- /dev/null +++ b/build/external_resources/webpack/readme.md @@ -0,0 +1,11 @@ +# webpack resource + +Ресурс должен быть tar-архивом с директорией node_modules, которая содержит +следующие пакеты: + * typescript@4.5.5 — нужен чтобы интерпретировать TS-код + * webpack@5.69.1 — сам вебпак, который будет использоваться для сборки бандла + * webpack-cli@4.9.2 — cli к этому вебпаку + * ts-loader@9.2.6 — используется по сути как плагин к webpack. Нужен, чтобы транспилировать TS to JS прямо на шаге вызова вебпака. В противном случае придётся делать два шага: транспиляцию отдельно и после генерацию бандла. + +Сгенерировать новую версию ресурса можно с использованием скрипта `generate-webpack-resource.sh`. + |