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

Commit

Permalink
feat: automatic JSX transform of esbuild (#490)
Browse files Browse the repository at this point in the history
* fix: jsx transform of esbuild

* fix: jsx transform

* chore: optimize code
  • Loading branch information
ClarkXia authored Aug 30, 2022
1 parent c2c697e commit 40ce2a5
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 309 deletions.
2 changes: 1 addition & 1 deletion packages/ice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"dotenv": "^16.0.0",
"dotenv-expand": "^8.0.3",
"ejs": "^3.1.6",
"esbuild": "^0.14.23",
"esbuild": "^0.14.51",
"esbuild-register": "^3.3.2",
"fast-glob": "^3.2.11",
"find-up": "^5.0.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/ice/src/polyfills/react.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/ice/src/service/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Config {
const { error } = await esbuildCompiler({
entryPoints: [entry],
format: 'esm',
inject: [],
outfile,
plugins: [removeTopLevelCode(keepExports, transformInclude)],
});
Expand Down
5 changes: 1 addition & 4 deletions packages/ice/src/service/serverCompiler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as path from 'path';
import { fileURLToPath } from 'url';
import { createHash } from 'crypto';
import * as fs from 'fs';
import consola from 'consola';
Expand All @@ -24,8 +23,6 @@ import { scanImports } from './analyze.js';
import type { DepsMetaData } from './preBundleCJSDeps.js';
import preBundleCJSDeps from './preBundleCJSDeps.js';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

interface Options {
rootDir: string;
task: TaskConfig<Config>;
Expand Down Expand Up @@ -112,7 +109,7 @@ export function createServerCompiler(options: Options) {
// enable JSX syntax in .js files by default for compatible with migrate project
// while it is not recommended
loader: { '.js': 'jsx' },
inject: [path.resolve(__dirname, '../polyfills/react.js')],
jsx: 'automatic',
sourcemap: typeof sourceMap === 'boolean'
// Transform sourceMap for esbuild.
? sourceMap : (sourceMap.includes('inline') ? 'inline' : !!sourceMap),
Expand Down
1 change: 0 additions & 1 deletion packages/ice/src/webpack/DataLoaderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default class DataLoaderPlugin {
target: 'esnext',
entryPoints: [filePath],
write: false,
inject: [],
}, {
swc: {
removeExportExprs: ['default', 'getConfig', 'getServerData', 'getStaticData'],
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-pha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"devDependencies": {
"@ice/types": "^1.0.0",
"esbuild": "^0.14.23",
"esbuild": "^0.14.51",
"webpack": "^5.73.0",
"webpack-dev-server": "^4.9.2"
},
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-pha/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const plugin: Plugin<PluginOptions> = (options) => ({
format: 'esm',
outfile,
minify,
inject: [],
});
return `${outfile}`;
};
Expand Down
10 changes: 10 additions & 0 deletions packages/plugin-rax-compat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ const plugin: Plugin<CompatRaxOptions> = (options = {}) => ({
},
},
});
if (!config.server) {
config.server = {};
}
const originalOptions = config.server.buildOptions;
config.server.buildOptions = (options) => ({
...(originalOptions ? originalOptions(options) : options),
jsx: 'transform',
jsxFactory: 'createElement',
jsxFragment: 'Fragment',
});
Object.assign(config.alias, alias);
if (options.inlineStyle) {
if (!warnOnce) {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@ice/route-manifest": "^1.0.0",
"@ice/runtime": "^1.0.0",
"build-scripts": "^2.0.0-24",
"esbuild": "^0.14.23",
"esbuild": "^0.14.51",
"eslint": "^8.14.0",
"eslint-webpack-plugin": "3.1.1",
"fork-ts-checker-webpack-plugin": "7.2.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"devDependencies": {
"@ice/types": "^1.0.0",
"build-scripts": "^2.0.0-24",
"esbuild": "^0.14.23",
"esbuild": "^0.14.51",
"webpack": "^5.73.0",
"webpack-dev-server": "^4.7.4"
},
Expand Down
Loading

1 comment on commit 40ce2a5

@vercel
Copy link

@vercel vercel bot commented on 40ce2a5 Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ice-v3 – ./

ice-v3-ice-v3.vercel.app
ice-v3.vercel.app
ice-v3-git-release-next-ice-v3.vercel.app

Please sign in to comment.