Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release-next' into fix/core-js
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia authored Nov 4, 2022
2 parents b011469 + 0222692 commit 9368c8f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/ice/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ const build = async (
spinner: ora.Ora;
getAppConfig: GetAppConfig;
getRoutesConfig: GetRoutesConfig;
userConfigHash: string;
},
) => {
const { taskConfigs, serverCompiler, spinner, getAppConfig, getRoutesConfig } = options;
const { taskConfigs, serverCompiler, spinner, getAppConfig, getRoutesConfig, userConfigHash } = options;
const { applyHook, rootDir } = context;
const webpackConfigs = taskConfigs.map(({ config }) => getWebpackConfig({
config,
rootDir,
// @ts-expect-error fix type error of compiled webpack
webpack,
runtimeTmpDir: RUNTIME_TMP_DIR,
userConfigHash,
}));
const outputDir = webpackConfigs[0].output.path;

Expand Down
3 changes: 3 additions & 0 deletions packages/ice/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const start = async (
spinner: ora.Ora;
getAppConfig: GetAppConfig;
getRoutesConfig: GetRoutesConfig;
userConfigHash: string;
},
) => {
const {
Expand All @@ -42,6 +43,7 @@ const start = async (
spinner,
getAppConfig,
getRoutesConfig,
userConfigHash,
} = options;
const { commandArgs, rootDir } = context;
const { platform = WEB } = commandArgs;
Expand All @@ -51,6 +53,7 @@ const start = async (
// @ts-expect-error fix type error of compiled webpack
webpack,
runtimeTmpDir: RUNTIME_TMP_DIR,
userConfigHash,
}));

const hooksAPI = {
Expand Down
10 changes: 10 additions & 0 deletions packages/ice/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,16 @@ const userConfig = [
config.splitChunks = splitChunks;
},
},
{
name: 'crossOriginLoading',
validation: 'boolean|string',
defaultValue: false,
setConfig: (config: Config, crossOriginLoading: UserConfig['crossOriginLoading']) => {
config.output = merge(config.output || {}, {
crossOriginLoading,
});
},
},
];

const cliOption = [
Expand Down
5 changes: 5 additions & 0 deletions packages/ice/src/createService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { CommandArgs, CommandName } from 'build-scripts';
import type { Config } from '@ice/webpack-config/esm/types';
import type { AppConfig } from '@ice/runtime/esm/types';
import webpack from '@ice/bundles/compiled/webpack/index.js';
import fg from 'fast-glob';
import type { DeclarationData } from './types/generator.js';
import type { PluginData, ExtendsPluginAPI } from './types/plugin.js';
import Generator from './service/runtimeGenerator.js';
Expand All @@ -29,6 +30,7 @@ import ServerCompileTask from './utils/ServerCompileTask.js';
import { getAppExportConfig, getRouteExportConfig } from './service/config.js';
import renderExportsTemplate from './utils/renderExportsTemplate.js';
import { getFileExports } from './service/analyze.js';
import { getFileHash } from './utils/hash.js';

const require = createRequire(import.meta.url);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
Expand Down Expand Up @@ -133,6 +135,7 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
// get userConfig after setup because of userConfig maybe modified by plugins
const { userConfig } = ctx;
const { routes: routesConfig, server, syntaxFeatures, polyfill } = userConfig;
const userConfigHash = await getFileHash(path.join(rootDir, fg.sync(configFile, { cwd: rootDir })[0]));

await setEnv(rootDir, commandArgs);
const coreEnvKeys = getCoreEnvKeys();
Expand Down Expand Up @@ -238,6 +241,7 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
appConfig,
devPath: (routePaths[0] || '').replace(/^[/\\]/, ''),
spinner: buildSpinner,
userConfigHash,
});
} else if (command === 'build') {
return await build(ctx, {
Expand All @@ -246,6 +250,7 @@ async function createService({ rootDir, command, commandArgs }: CreateServiceOpt
taskConfigs,
serverCompiler,
spinner: buildSpinner,
userConfigHash,
});
} else if (command === 'test') {
return await test(ctx, {
Expand Down
1 change: 1 addition & 0 deletions packages/ice/src/types/userConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ export interface UserConfig {
syntaxFeatures?: SyntaxFeatures;
splitChunks?: boolean;
dataLoader?: boolean;
crossOriginLoading?: Config['output']['crossOriginLoading'];
}
5 changes: 3 additions & 2 deletions packages/webpack-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface GetWebpackConfigOptions {
config: Config;
webpack: typeof webpack;
runtimeTmpDir: string;
userConfigHash: string;
}
type GetWebpackConfig = (options: GetWebpackConfigOptions) => Configuration;
enum JSMinifier {
Expand All @@ -59,7 +60,7 @@ function getEntry(rootDir: string, runtimeTmpDir: string) {
};
}

const getWebpackConfig: GetWebpackConfig = ({ rootDir, config, webpack, runtimeTmpDir }) => {
const getWebpackConfig: GetWebpackConfig = ({ rootDir, config, webpack, runtimeTmpDir, userConfigHash }) => {
const {
mode,
define = {},
Expand Down Expand Up @@ -260,7 +261,7 @@ const getWebpackConfig: GetWebpackConfig = ({ rootDir, config, webpack, runtimeT
} as Configuration['optimization'],
cache: {
type: 'filesystem',
version: `${process.env.__ICE_VERSION__}|${JSON.stringify(config)}`,
version: `${process.env.__ICE_VERSION__}|${userConfigHash}`,
buildDependencies: { config: [path.join(rootDir, 'package.json')] },
cacheDirectory: path.join(cacheDir, 'webpack'),
},
Expand Down
17 changes: 17 additions & 0 deletions website/docs/guide/basic/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ export default defineConfig({
});
```

### crossOriginLoading

- 类型:`false | 'anonymous' | 'use-credentials'`
- 默认值:`false`

配置

```js
import { defineConfig } from '@ice/app';

export default defineConfig({
crossOriginLoading: 'anonymous'
});
```

指定 webpack 启用 [cross-origin](https://webpack.js.org/configuration/output/#outputcrossoriginloading) 去加载 chunk。

### define

- 类型:`Record<string, string | boolean>`
Expand Down

0 comments on commit 9368c8f

Please sign in to comment.