diff --git a/examples/basic-spa/build.json b/examples/basic-spa/build.json index b138abd511..76c19f75a4 100644 --- a/examples/basic-spa/build.json +++ b/examples/basic-spa/build.json @@ -9,6 +9,5 @@ "eslint": { "disable": false, "quiet": true - }, - "tsChecker": true + } } diff --git a/examples/basic-spa/src/app.tsx b/examples/basic-spa/src/app.tsx index 2add7b16ac..4b3514e78c 100644 --- a/examples/basic-spa/src/app.tsx +++ b/examples/basic-spa/src/app.tsx @@ -1,11 +1,15 @@ import React from 'react'; -import { createApp, APP_MODE, IAppConfig } from 'ice'; +import { createApp, APP_MODE, IAppConfig, request } from 'ice'; const appConfig: IAppConfig = { app: { rootId: 'ice-container', errorBoundary: true, parseSearchParams: true, + getInitialData: async() => { + const result = await request('/repo'); + console.log('request result:', result); + }, onShow() { console.log('app show...'); }, @@ -23,7 +27,7 @@ const appConfig: IAppConfig = { }, request: { timeout: 5000, - baseURL: '/', + baseURL: '/api', interceptors: { request: { onConfig: (config) => { diff --git a/packages/create-app-shared/package.json b/packages/create-app-shared/package.json index 56d85b67b8..b959e88152 100644 --- a/packages/create-app-shared/package.json +++ b/packages/create-app-shared/package.json @@ -1,6 +1,6 @@ { "name": "create-app-shared", - "version": "0.1.8", + "version": "0.1.9", "description": "", "author": "ice-admin@alibaba-inc.com", "homepage": "https://github.com/alibaba/ice#readme", diff --git a/packages/create-app-shared/src/createBaseApp.ts b/packages/create-app-shared/src/createBaseApp.ts index d9a460f64f..d781c3f140 100644 --- a/packages/create-app-shared/src/createBaseApp.ts +++ b/packages/create-app-shared/src/createBaseApp.ts @@ -15,14 +15,12 @@ const DEFAULE_APP_CONFIG = { } }; -export default ({ loadRuntimeModules, loadStaticModules, createElement }) => { +export default ({ loadRuntimeModules, createElement }) => { const createBaseApp = (appConfig, buildConfig, context: any = {}) => { + // Merge default appConfig to user appConfig appConfig = deepmerge(DEFAULE_APP_CONFIG, appConfig); - // load module to run before createApp ready - loadStaticModules(appConfig); - // Set history let history = {}; if (!isMiniAppPlatform) { diff --git a/packages/create-app-shared/src/index.ts b/packages/create-app-shared/src/index.ts index e4934c8269..92b1a9526b 100644 --- a/packages/create-app-shared/src/index.ts +++ b/packages/create-app-shared/src/index.ts @@ -14,10 +14,10 @@ import useSearchParams from './useSearchParams'; import withSearchParams from './withSearchParams'; import collectAppLifeCycle from './collectAppLifeCycle'; -function createShareAPI({ withRouter, createElement, useEffect }, loadRuntimeModules, loadStaticModules) { +function createShareAPI({ withRouter, createElement, useEffect }, loadRuntimeModules) { const { usePageShow, usePageHide } = createUsePageLifeCycle({ useEffect }); return { - createBaseApp: createBaseApp({ loadRuntimeModules, loadStaticModules, createElement }), + createBaseApp: createBaseApp({ loadRuntimeModules, createElement }), // history api withRouter: enhanceWithRouter({ withRouter, createElement }), diff --git a/packages/icejs/package.json b/packages/icejs/package.json index 017465ad15..9a3cb01809 100644 --- a/packages/icejs/package.json +++ b/packages/icejs/package.json @@ -1,6 +1,6 @@ { "name": "ice.js", - "version": "1.7.2", + "version": "1.7.3", "description": "command line interface and builtin plugin for icejs", "author": "ice-admin@alibaba-inc.com", "homepage": "", @@ -26,15 +26,15 @@ "dependencies": { "@alib/build-scripts": "^0.1.13", "build-plugin-ice-config": "1.7.0", - "build-plugin-app-core": "0.1.10", + "build-plugin-app-core": "0.1.11", "build-plugin-ice-helpers": "1.7.0", "build-plugin-ice-logger": "1.7.0", "build-plugin-ice-mpa": "1.7.0", "build-plugin-ice-request": "1.7.1", "build-plugin-ice-router": "1.7.1", - "build-plugin-ice-ssr": "1.7.0", + "build-plugin-ice-ssr": "1.7.1", "build-plugin-ice-store": "1.7.1", - "build-plugin-react-app": "1.7.1", + "build-plugin-react-app": "1.7.2", "build-plugin-miniapp": "0.1.2", "create-cli-utils": "^0.1.0", "chokidar": "^3.3.1", diff --git a/packages/plugin-app-core/package.json b/packages/plugin-app-core/package.json index 709bd960fb..500d88d2d6 100644 --- a/packages/plugin-app-core/package.json +++ b/packages/plugin-app-core/package.json @@ -1,6 +1,6 @@ { "name": "build-plugin-app-core", - "version": "0.1.10", + "version": "0.1.11", "description": "the core plugin for icejs and raxjs.", "author": "ice-admin@alibaba-inc.com", "homepage": "", diff --git a/packages/plugin-app-core/src/generator/templates/common/runApp.ts.ejs b/packages/plugin-app-core/src/generator/templates/common/runApp.ts.ejs index 6051ca6842..99691ea04a 100644 --- a/packages/plugin-app-core/src/generator/templates/common/runApp.ts.ejs +++ b/packages/plugin-app-core/src/generator/templates/common/runApp.ts.ejs @@ -43,7 +43,7 @@ const { createElement, useEffect, withRouter: defaultWithRouter -}, loadRuntimeModules, loadStaticModules); +}, loadRuntimeModules); export function runApp(appConfig) { let renderer; @@ -65,6 +65,7 @@ export function runApp(appConfig) { getHistory, emitLifeCycles, pathRedirect, + loadStaticModules, ErrorBoundary }, { createElement, diff --git a/packages/plugin-app-core/src/utils/getSourceDir.ts b/packages/plugin-app-core/src/utils/getSourceDir.ts index 58beaebd00..65605fbfe6 100644 --- a/packages/plugin-app-core/src/utils/getSourceDir.ts +++ b/packages/plugin-app-core/src/utils/getSourceDir.ts @@ -1,4 +1,4 @@ -import * as path from 'path'; +import formatPath from './formatPath'; // entry: src/app -> srcDir: src // entry: client/app -> srcDir: client @@ -14,7 +14,9 @@ function getSourceDir (entry): string { } } - return entryStr.split(path.sep)[0]; + entryStr = formatPath(entryStr); + + return entryStr.split('/')[0]; } export default getSourceDir; diff --git a/packages/plugin-react-app/package.json b/packages/plugin-react-app/package.json index 947b392b70..b95d8c76d0 100644 --- a/packages/plugin-react-app/package.json +++ b/packages/plugin-react-app/package.json @@ -1,6 +1,6 @@ { "name": "build-plugin-react-app", - "version": "1.7.1", + "version": "1.7.2", "description": "The basic webpack configuration for ice project", "author": "ice-admin@alibaba-inc.com", "main": "src/index.js", diff --git a/packages/plugin-react-app/src/base.js b/packages/plugin-react-app/src/base.js index d2b66d0436..09a625486a 100644 --- a/packages/plugin-react-app/src/base.js +++ b/packages/plugin-react-app/src/base.js @@ -11,11 +11,9 @@ const collect = require('./utils/collect'); // eslint-disable-next-line const chalk = require('chalk'); -module.exports = (api) => { +module.exports = (api, { isMiniapp }) => { const { context, log } = api; - const { command, rootDir, webpack, commandArgs, pkg, userConfig: { targets } } = context; - const isMiniapp = Array.isArray(targets) - && (targets.includes('miniapp') || targets.includes('wechat-miniprogram')); + const { command, rootDir, webpack, commandArgs, pkg } = context; const appMode = commandArgs.mode || command; collect({ command, log, rootDir, pkg }); const babelConfig = getBabelConfig(); diff --git a/packages/plugin-react-app/src/index.js b/packages/plugin-react-app/src/index.js index a6be22db2f..5b92ec269e 100644 --- a/packages/plugin-react-app/src/index.js +++ b/packages/plugin-react-app/src/index.js @@ -14,8 +14,7 @@ module.exports = (api) => { const { onGetJestConfig, onGetWebpackConfig, context, registerTask, onHook } = api; const { command, rootDir, commandArgs, userConfig } = context; const { targets = [WEB] } = userConfig; - const isMiniapp = Array.isArray(targets) - && (targets.includes(MINIAPP) || targets.includes(WECHAT_MINIPROGRAM)); + const isMiniapp = targets.includes(MINIAPP) || targets.includes(WECHAT_MINIPROGRAM); // register cli option registerCliOption(api); @@ -32,7 +31,7 @@ module.exports = (api) => { chainConfig.resolve.modules.add(path.join(rootDir, 'node_modules')); }); - targets.forEach(target => registerTask(target, getBase(api))); + targets.forEach(target => registerTask(target, getBase(api, { isMiniapp }))); if (command === 'test') { onGetJestConfig((jestConfig) => { diff --git a/packages/plugin-react-app/src/utils/getMiniappOutputPath.js b/packages/plugin-react-app/src/utils/getMiniappOutputPath.js index 42f01e059d..babca5ae33 100644 --- a/packages/plugin-react-app/src/utils/getMiniappOutputPath.js +++ b/packages/plugin-react-app/src/utils/getMiniappOutputPath.js @@ -1,10 +1,11 @@ const fs = require('fs-extra'); const path = require('path'); const { MINIAPP } = require('../constants'); +const defaultConfig = require('../config/default.config'); module.exports = (context, options = {}) => { const { rootDir, userConfig } = context; - const { outputDir } = userConfig; + const { outputDir = defaultConfig.outputDir } = userConfig; const output = path.resolve(rootDir, outputDir); fs.ensureDirSync(output); return path.resolve(output, options.target || MINIAPP); diff --git a/packages/plugin-ssr/package.json b/packages/plugin-ssr/package.json index a0dc295edd..1876f8043d 100644 --- a/packages/plugin-ssr/package.json +++ b/packages/plugin-ssr/package.json @@ -1,6 +1,6 @@ { "name": "build-plugin-ice-ssr", - "version": "1.7.0", + "version": "1.7.1", "description": "ssr plugin", "author": "ice-admin@alibaba-inc.com", "homepage": "", diff --git a/packages/plugin-ssr/src/server.ts.ejs b/packages/plugin-ssr/src/server.ts.ejs index ba3fb0e6b4..db42744a42 100644 --- a/packages/plugin-ssr/src/server.ts.ejs +++ b/packages/plugin-ssr/src/server.ts.ejs @@ -44,15 +44,14 @@ const serverRender = async ({ context, pathname, initialData, htmlTemplate }) => // generate bundle content and register global variables in html console.log('[SSR]', 'generating html content'); const bundleContent = reactAppRendererWithSSR({ + staticContext: context, + pathname, + initialData, + pageInitialProps + }, { appConfig, createBaseApp, - emitLifeCycles, - context: { - staticContext: context, - pathname, - initialData, - pageInitialProps - } + emitLifeCycles }); $('#ice-container').append(bundleContent); $('head').append(`