Skip to content

Commit 9e5b5a2

Browse files
author
weimin2.zhou
committed
WIP: CodeFuse IDE Support Web IDE codefuse-ai#32
1 parent 76e24ca commit 9e5b5a2

19 files changed

+942
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jspm_packages/
8181
dist
8282
lib
8383
out
84+
dist-node
8485
.vscode/*
8586
!.vscode/launch.json
8687

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ yarn run electron-rebuild
4343
yarn run start
4444
```
4545

46+
### Start the project (web)
47+
```bash
48+
# install dependencies
49+
yarn
50+
# rebuild native dependencies for electron
51+
yarn run electron-rebuild
52+
# start project
53+
yarn run start-web
54+
```
55+
4656
## Links
4757

4858
- **CodeFuse**: https://codefuse.ai
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
4+
const CopyPlugin = require('copy-webpack-plugin');
5+
const HtmlWebpackPlugin = require('html-webpack-plugin');
6+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
7+
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
8+
9+
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
10+
const webpack = require('webpack');
11+
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
12+
const TerserJSPlugin = require('terser-webpack-plugin');
13+
const product = require("../../product.json");
14+
const tsConfigPath = path.join(__dirname, '../../tsconfig.json');
15+
const srcDir = path.join(__dirname, '../../src/web/browser');
16+
const distDir = path.join(__dirname, '../../out');
17+
const publicDir = path.join(__dirname, '../../public');
18+
19+
const styleLoader =
20+
process.env.NODE_ENV === 'production' ? MiniCssExtractPlugin.loader : require.resolve('style-loader');
21+
const isDevelopment =
22+
process.env['NODE_ENV'] === 'development' || process.env['NODE_ENV'] === 'dev';
23+
24+
const port = 8080;
25+
26+
const idePkg = JSON.parse(
27+
fs
28+
.readFileSync(
29+
path.join(__dirname, '../..', './node_modules/@opensumi/ide-core-browser/package.json'),
30+
)
31+
.toString(),
32+
);
33+
34+
/** @type { import('webpack').Configuration } */
35+
module.exports = {
36+
entry: path.join(srcDir, './index.ts'),
37+
output: {
38+
filename: 'bundle.js',
39+
path: distDir,
40+
},
41+
cache: {
42+
type: 'filesystem',
43+
},
44+
45+
resolve: {
46+
extensions: ['.ts', '.tsx', '.js', '.json', '.less'],
47+
plugins: [
48+
new TsconfigPathsPlugin({
49+
configFile: tsConfigPath,
50+
}),
51+
],
52+
fallback: {
53+
net: false,
54+
path: false,
55+
os: false,
56+
crypto: false,
57+
child_process: false,
58+
url: false,
59+
fs: false,
60+
},
61+
},
62+
mode: process.env['NODE_ENV'],
63+
devtool: 'source-map',
64+
module: {
65+
// https://github.com/webpack/webpack/issues/196#issuecomment-397606728
66+
exprContextCritical: false,
67+
rules: [
68+
{
69+
test: /\.tsx?$/,
70+
loader: 'ts-loader',
71+
options: {
72+
happyPackMode: true,
73+
transpileOnly: true,
74+
configFile: tsConfigPath,
75+
compilerOptions: {
76+
target: 'es2016',
77+
},
78+
},
79+
},
80+
{
81+
test: /\.png$/,
82+
type: 'asset/resource',
83+
},
84+
85+
{
86+
test: /\.css$/,
87+
use: [styleLoader, 'css-loader'],
88+
},
89+
{
90+
test: /\.module.less$/,
91+
use: [
92+
styleLoader,
93+
{
94+
loader: 'css-loader',
95+
options: {
96+
sourceMap: true,
97+
modules: {
98+
localIdentName: '[local]___[hash:base64:5]',
99+
},
100+
},
101+
},
102+
{
103+
loader: 'less-loader',
104+
options: {
105+
lessOptions: {
106+
javascriptEnabled: true,
107+
},
108+
},
109+
},
110+
],
111+
},
112+
{
113+
test: /^((?!\.module).)*less$/,
114+
use: [
115+
styleLoader,
116+
{
117+
loader: 'css-loader',
118+
},
119+
{
120+
loader: 'less-loader',
121+
options: {
122+
lessOptions: {
123+
javascriptEnabled: true,
124+
},
125+
},
126+
},
127+
],
128+
},
129+
{
130+
test: /\.svg$/,
131+
type: 'asset/resource',
132+
generator: {
133+
filename: 'images/[name].[hash][ext][query]',
134+
},
135+
},
136+
{
137+
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
138+
type: 'asset/resource',
139+
generator: {
140+
filename: 'fonts/[name]-[hash:8][ext][query]',
141+
},
142+
},
143+
],
144+
},
145+
resolveLoader: {
146+
modules: [path.join(__dirname, '../../node_modules')],
147+
extensions: ['.ts', '.tsx', '.js', '.json', '.less'],
148+
mainFields: ['loader', 'main'],
149+
},
150+
plugins: [
151+
new HtmlWebpackPlugin({
152+
template: path.join(publicDir, 'index.html'),
153+
}),
154+
new MiniCssExtractPlugin({
155+
filename: '[name].[chunkhash:8].css',
156+
chunkFilename: '[id].css',
157+
}),
158+
!process.env.CI && new webpack.ProgressPlugin(),
159+
new NodePolyfillPlugin({
160+
includeAliases: ['path', 'Buffer', 'process'],
161+
}),
162+
new webpack.DefinePlugin({
163+
__PRODUCT__: JSON.stringify(product),
164+
'process.env.WORKSPACE_DIR': JSON.stringify(
165+
isDevelopment ? path.join(__dirname, '../..', 'workspace') : process.env['WORKSPACE_DIR'],
166+
),
167+
'process.env.EXTENSION_DIR': JSON.stringify(
168+
isDevelopment ? path.join(__dirname, '../..', 'extensions') : process.env['EXTENSION_DIR'],
169+
),
170+
'process.env.REVERSION': JSON.stringify(idePkg.version || 'alpha'),
171+
'process.env.DEVELOPMENT': JSON.stringify(!!isDevelopment),
172+
'process.env.TEMPLATE_TYPE': JSON.stringify(
173+
isDevelopment ? process.env['TEMPLATE_TYPE'] : 'standard',
174+
),
175+
}),
176+
new CopyPlugin({
177+
patterns: [{
178+
from: publicDir,
179+
to: distDir,
180+
filter: (filepath) => {
181+
console.log("filepath", filepath);
182+
return !filepath.endsWith('index.html')
183+
}
184+
}]
185+
}),
186+
187+
],
188+
optimization: {
189+
nodeEnv: process.env.NODE_ENV,
190+
minimizer: [
191+
new TerserJSPlugin({
192+
minify: TerserJSPlugin.esbuildMinify,
193+
194+
}),
195+
new OptimizeCSSAssetsPlugin({}),
196+
],
197+
},
198+
devServer: {
199+
static: {
200+
directory: path.join(__dirname, '../../out'), // 静态文件目录
201+
},
202+
port,
203+
host: '0.0.0.0',
204+
headers: {
205+
'Access-Control-Allow-Origin': '*',
206+
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
207+
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
208+
},
209+
open: true,
210+
client: {
211+
overlay: {
212+
errors: true,
213+
warnings: false,
214+
runtimeErrors: false,
215+
},
216+
},
217+
}
218+
219+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import path from 'node:path';
2+
import {DefinePlugin} from 'webpack';
3+
import {createConfig, webpackDir} from '../webpack/webpack.base.config';
4+
import {asarDeps} from '../deps'
5+
6+
const srcDir = path.resolve('src/bootstrap/ext-host');
7+
const outDir = path.join(webpackDir, 'ext-host');
8+
9+
module.exports = createConfig((_, argv) => ({
10+
entry: srcDir,
11+
output: {
12+
filename: 'index.js',
13+
path: outDir,
14+
},
15+
externals: [
16+
({request}, callback) => {
17+
if (asarDeps.includes(request!)) {
18+
return callback(null, 'commonjs ' + request);
19+
}
20+
callback();
21+
},
22+
],
23+
plugins: [
24+
new DefinePlugin({
25+
'process.env.IDE_DATA_FOLDER_NAME': JSON.stringify('.codefuse-ide'),
26+
'process.env.CODE_WINDOW_CLIENT_ID': JSON.stringify('CODE_WINDOW_CLIENT_ID'),
27+
'process.env.IDE_LOG_HOME': JSON.stringify('logs')
28+
})
29+
],
30+
target: 'node',
31+
}))
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
4+
5+
const tsConfigPath = path.join(__dirname, '../..', '/tsconfig.json');
6+
const srcDir = path.join(__dirname, '../..', 'src', 'web', 'node');
7+
const distDir = path.join(__dirname, '../..', 'dist-node', 'server');
8+
9+
module.exports = {
10+
entry: path.join(srcDir, './index.ts'),
11+
target: 'node',
12+
output: {
13+
filename: 'index.js',
14+
path: distDir,
15+
clean: true,
16+
},
17+
node: false,
18+
// mode: process.env.NODE_ENV || 'development',
19+
mode: "production",
20+
devtool: 'source-map',
21+
optimization: {
22+
minimize: true,
23+
},
24+
cache: {
25+
type: 'filesystem',
26+
},
27+
watch: false,
28+
resolve: {
29+
extensions: ['.ts', '.tsx', '.js', '.json'],
30+
plugins: [
31+
new TsconfigPathsPlugin({
32+
configFile: tsConfigPath,
33+
}),
34+
],
35+
},
36+
module: {
37+
exprContextCritical: false,
38+
rules: [
39+
{
40+
test: /\.tsx?$/,
41+
use: [
42+
{
43+
loader: 'ts-loader',
44+
options: {
45+
happyPackMode: true,
46+
transpileOnly: true,
47+
configFile: tsConfigPath,
48+
compilerOptions: {
49+
target: 'es2016',
50+
},
51+
},
52+
},
53+
],
54+
},
55+
{test: /\.css$/, loader: 'null-loader'},
56+
{test: /\.less$/, loader: 'null-loader'},
57+
],
58+
},
59+
externals: [
60+
function ({request}, callback) {
61+
if (
62+
[
63+
'node-pty',
64+
'oniguruma',
65+
'@parcel/watcher',
66+
'@vscode/spdlog',
67+
'nsfw',
68+
'spdlog',
69+
'vm2',
70+
'canvas',
71+
'@opensumi/vscode-ripgrep',
72+
'vertx',
73+
'keytar',
74+
'tsconfig-paths',
75+
].indexOf(request) !== -1
76+
) {
77+
return callback(null, `commonjs ${request}`);
78+
}
79+
callback();
80+
},
81+
],
82+
resolveLoader: {
83+
extensions: ['.ts', '.tsx', '.js', '.json'],
84+
mainFields: ['loader', 'main'],
85+
modules: [
86+
path.join(__dirname, '../../../node_modules'),
87+
path.join(__dirname, '../node_modules'),
88+
path.resolve('node_modules'),
89+
],
90+
},
91+
92+
plugins: [
93+
!process.env.CI && new webpack.ProgressPlugin(),
94+
new webpack.DefinePlugin({
95+
'process.env.IDE_DATA_FOLDER_NAME': JSON.stringify('.codefuse-ide'),
96+
'process.env.CODE_WINDOW_CLIENT_ID': JSON.stringify('CODE_WINDOW_CLIENT_ID'),
97+
'process.env.IDE_LOG_HOME': JSON.stringify('logs')
98+
99+
})
100+
],
101+
}

0 commit comments

Comments
 (0)