Skip to content

Commit

Permalink
fix: conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjun1011 committed Oct 23, 2023
2 parents 7544aff + a7fd208 commit f367dc2
Show file tree
Hide file tree
Showing 69 changed files with 1,035 additions and 1,499 deletions.
5 changes: 0 additions & 5 deletions .changeset/curly-bears-mate.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/empty-ads-sleep.md

This file was deleted.

1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules/
dist/
out/
compiled/
public/

# node 覆盖率文件
coverage/
Expand Down
3 changes: 3 additions & 0 deletions examples/basic-project/ice.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ export default defineConfig(() => ({
customPlugin(),
],
eslint: true,
cssModules: {
localIdentName: '[hash:8]',
},
}));
6 changes: 3 additions & 3 deletions examples/basic-project/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineAppConfig, defineDataLoader } from 'ice';
import { defineAppConfig, defineDataLoader, defineRunApp } from 'ice';
import { isWeb, isNode } from '@uni/env';

if (process.env.ICE_CORE_ERROR_BOUNDARY === 'true') {
Expand Down Expand Up @@ -43,6 +43,6 @@ export const dataLoader = defineDataLoader(() => {
});
});

export const runApp = (render) => {
export const runApp = defineRunApp((render) => {
render();
};
});
4 changes: 4 additions & 0 deletions examples/csr-project/ice.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export default defineConfig(() => ({
}
return webpackConfig;
},
server: {
onDemand: true,
format: 'esm',
},
dropLogLevel: 'warn',
plugins: [
auth(),
Expand Down
4 changes: 3 additions & 1 deletion examples/hash-router/src/pages/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Outlet } from 'ice';
import { Outlet, useConfig } from 'ice';

export default () => {
const config = useConfig();
return (
<div>
<h1>Layout</h1>
<h3>{config.title}</h3>
<Outlet />
</div>
);
Expand Down
13 changes: 13 additions & 0 deletions examples/icestark-layout/ice.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,18 @@ export default defineConfig(() => ({
icestark({
type: 'framework',
}),
{
setup({ onGetConfig }) {
// Enable option `enableCopyPlugin`, so devserver can access public folder when run test.
if (process.env.NODE_ENV === 'test') {
onGetConfig((config) => {
return {
...config,
enableCopyPlugin: true,
}
});
}
}
}
]
}));

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions examples/icestark-layout/public/page-seller/assets/index.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions examples/icestark-layout/public/page-seller/assets/vendor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/icestark-layout/public/page-seller/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1"><meta name="viewport" content="width=device-width"><title>icestark</title><link rel="stylesheet" href="/page-seller/assets/index.css"></head><body><div id="ice-container"></div><script type="module" src="/page-seller/assets/index.js"></script><script type="module" src="/page-seller/assets/vendor.js"></script></body></html>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/icestark-layout/public/page-waiter/assets/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/icestark-layout/public/page-waiter/assets/vendor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/icestark-layout/public/page-waiter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Vite App</title><link rel="stylesheet" href="/page-waiter/assets/main.css"></head><body><div id="app"></div><script type="module" src="/page-waiter/assets/main.js"></script></body></html>
4 changes: 2 additions & 2 deletions examples/icestark-layout/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export const icestark = defineFrameworkConfig(() => ({
path: '/seller',
title: '商家平台',
loadScriptMode: 'import',
entry: 'https://iceworks.oss-cn-hangzhou.aliyuncs.com/icestark/child-seller-ice-vite/index.html',
entry: '/page-seller/index.html',
}, {
path: '/waiter',
title: '小二平台',
loadScriptMode: 'import',
entry: 'https://iceworks.oss-cn-hangzhou.aliyuncs.com/icestark/child-vue3-vite/index.html',
entry: '/page-waiter/index.html',
}]),
}));

Expand Down
2 changes: 1 addition & 1 deletion packages/bundles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"events": "3.3.0",
"jest-worker": "27.5.1",
"less": "4.1.2",
"postcss": "8.4.12",
"postcss": "8.4.31",
"sass": "1.50.0",
"react-refresh": "0.14.0",
"core-js-pure": "^3.8.1",
Expand Down
33 changes: 33 additions & 0 deletions packages/ice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# Changelog

## 3.3.4

### Patch Changes

- ca14f6d3: fix: compatible with configureWebpack in speedup mode
- 244bb17f: add typesVersions for export fields support
- 6f18c3db: fix: deal with json file when use on-demand compile
- 1de19371: feat: add type definition of runApp
- 7924f2d1: fix: return render root
- 93e868d3: fix: hasDocument should check jsx
- aa29b37b: fix: get flatten routes which nested level more than 3
- Updated dependencies [ca14f6d3]
- Updated dependencies [df854102]
- Updated dependencies [50efd1ee]
- Updated dependencies [4d256e30]
- Updated dependencies [50efd1ee]
- @ice/webpack-config@1.1.4
- @ice/rspack-config@1.0.5
- @ice/shared-config@1.1.0
- @ice/runtime@1.3.0

## 3.3.3

### Patch Changes

- c3a9c20a: chore: modify output
- 82702258: feat: compat no document
- 78f850fa: feat: support hash only class name for css modules
- Updated dependencies [78f850fa]
- @ice/webpack-config@1.1.3
- @ice/shared-config@1.0.4
- @ice/rspack-config@1.0.4

## 3.3.2

### Patch Changes
Expand Down
25 changes: 19 additions & 6 deletions packages/ice/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/app",
"version": "3.3.2",
"version": "3.3.4",
"description": "provide scripts and configuration used by web framework ice",
"type": "module",
"main": "./esm/index.js",
Expand All @@ -10,6 +10,19 @@
"./analyze": "./esm/service/analyze.js",
"./service": "./esm/createService.js"
},
"typesVersions": {
"*": {
"types": [
"./esm/types/index.d.ts"
],
"analyze": [
"./esm/service/analyze.d.ts"
],
"service": [
"./esm/createService.d.ts"
]
}
},
"bin": {
"ice": "./bin/ice-cli.mjs"
},
Expand Down Expand Up @@ -39,10 +52,10 @@
"dependencies": {
"@ice/bundles": "0.1.16",
"@ice/route-manifest": "1.2.2",
"@ice/runtime": "^1.2.9",
"@ice/shared-config": "1.0.3",
"@ice/webpack-config": "1.1.2",
"@ice/rspack-config": "1.0.3",
"@ice/runtime": "^1.3.0",
"@ice/shared-config": "1.1.0",
"@ice/webpack-config": "1.1.4",
"@ice/rspack-config": "1.0.5",
"@swc/helpers": "0.5.1",
"@types/express": "^4.17.14",
"address": "^1.1.2",
Expand Down Expand Up @@ -98,4 +111,4 @@
"publishConfig": {
"access": "public"
}
}
}
7 changes: 5 additions & 2 deletions packages/ice/src/bundler/rspack/getConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import getRspackConfig from '@ice/rspack-config';
import type { Configuration } from '@rspack/core';
import type { rspack as Rspack } from '@ice/bundles/esm/rspack.js';
import type { Config } from '@ice/shared-config/types';
import { getRouteExportConfig } from '../../service/config.js';
import {
Expand All @@ -16,10 +17,11 @@ import type { BundlerOptions, Context } from '../types.js';

type GetConfig = (
context: Context,
options: BundlerOptions
options: BundlerOptions,
rspack: typeof Rspack,
) => Promise<Configuration[]>;

const getConfig: GetConfig = async (context, options) => {
const getConfig: GetConfig = async (context, options, rspack) => {
const {
taskConfigs,
spinner,
Expand Down Expand Up @@ -73,6 +75,7 @@ const getConfig: GetConfig = async (context, options) => {
const plugins = getPlugins(config);
return getRspackConfig({
rootDir,
rspack,
runtimeTmpDir: RUNTIME_TMP_DIR,
runtimeDefineVars: {
[IMPORT_META_TARGET]: JSON.stringify(config.target),
Expand Down
5 changes: 2 additions & 3 deletions packages/ice/src/bundler/rspack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ async function bundler(
routeManifest,
appConfig,
} = options;
const rspackConfigs = await getConfig(context, options);

let compiler: MultiCompiler;
let devServer: RspackDevServer;
const { rspack } = await import('@ice/bundles/esm/rspack.js');
const rspackConfigs = await getConfig(context, options, rspack);
try {
const { rspack } = await import('@ice/bundles/esm/rspack.js');
compiler = rspack(rspackConfigs);
} catch (error) {
logger.error('Webpack compile error.');
Expand Down
8 changes: 8 additions & 0 deletions packages/ice/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ const userConfig = [
return mergeDefaultValue(config, 'postcss', postcss);
},
},
{
name: 'cssModules',
validation: 'object',
defaultValue: {},
setConfig(config: Config, postcss: UserConfig['cssModules']) {
return mergeDefaultValue(config, 'cssModules', postcss);
},
},
{
name: 'webpack',
validation: 'function',
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/src/createService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
enableRoutes: true,
entryCode,
jsOutput: distType.includes('javascript'),
hasDocument: fse.existsSync(path.join(rootDir, 'src/document.tsx')),
hasDocument: fse.existsSync(path.join(rootDir, 'src/document.tsx')) || fse.existsSync(path.join(rootDir, 'src/document.jsx')) || fse.existsSync(path.join(rootDir, 'src/document.js')),
dataLoader: userConfig.dataLoader,
routeImports,
routeDefinition,
Expand Down
30 changes: 24 additions & 6 deletions packages/ice/src/service/ServerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ interface InitOptions {
type ResolveCallback = Parameters<PluginBuild['onResolve']>[1];
type LoadCallback = Parameters<PluginBuild['onLoad']>[1];

const FALLBACK_LOADERS = {
'.json': 'json',
'.txt': 'text',
};

function getPluginLifecycle(plugin: Plugin, compiler: 'onLoad'): [OnResolveOptions, LoadCallback][];
function getPluginLifecycle(plugin: Plugin, compiler: 'onResolve'): [OnResolveOptions, ResolveCallback][];
function getPluginLifecycle(plugin: Plugin, hookKey: 'onResolve' | 'onLoad') {
Expand Down Expand Up @@ -67,7 +72,7 @@ async function transformJsxRuntime(source: string) {
}
// JSX runtime is added after swc plugins
// use es-module-lexer to replace the import statement.
if (imp.n === '@ice/runtime/jsx-dev-runtime') {
if (imp.n === '@ice/runtime/jsx-dev-runtime' || imp.n === '@ice/runtime/react/jsx-dev-runtime') {
str().overwrite(
imp.ss,
imp.se,
Expand Down Expand Up @@ -112,14 +117,16 @@ class ServerRunner extends Runner {
},
},
}, 'esbuild', { isServer: true });
const { alias, ignores } = filterAlias(task.config.alias || {});
const define = getRuntimeDefination(task.config.define || {});
const taskConfig = task.config;
const { alias, ignores } = filterAlias(taskConfig.alias || {});
const define = getRuntimeDefination(taskConfig.define || {});
const runtimeMeta = new RuntimeMeta({
rootDir,
alias,
ignores,
external: server.externals || [],
define,
taskConfig,
speedup,
});

Expand All @@ -140,8 +147,9 @@ class ServerRunner extends Runner {
// ServerRunner only works in development mode.
mode: 'development',
fileName,
localIdentName: name,
localName: name,
rule: speedup ? 'native' : 'loader',
localIdentName: taskConfig.cssModules?.localIdentName,
});
},
}),
Expand Down Expand Up @@ -260,11 +268,21 @@ class ServerRunner extends Runner {
...args,
path: formatedId,
});

// If res is undefined, it means the plugin does not handle the file, fallback to default handler.
if (!res && FALLBACK_LOADERS[path.extname(formatedId)]) {
res = {
loader: FALLBACK_LOADERS[path.extname(formatedId)],
};
}
if (res) {
const { contents, loader } = res;
if (['json', 'text'].includes(loader)) {
code = `__ice_exports__.default = ${contents || JSON.stringify(await fse.readFile(formatedId, 'utf-8'))}`;
if (contents) {
code = `__ice_exports__.default = ${contents}`;
} else {
const contents = await fse.readFile(formatedId, 'utf-8');
code = `__ice_exports__.default = ${loader === 'text' ? JSON.stringify(contents) : contents}`;
}
} else {
code = typeof contents === 'string' ? contents : contents.toString();
}
Expand Down
Loading

0 comments on commit f367dc2

Please sign in to comment.