Skip to content

Commit 556e886

Browse files
author
winjo
committed
feat: add shared package
1 parent 77adf3e commit 556e886

5 files changed

Lines changed: 1554 additions & 76 deletions

File tree

packages/cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @alipay/spacex-cli

packages/shared/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @alipay/spacex-shared

packages/shared/package.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "@alipay/spacex-shared",
3+
"version": "0.0.1",
4+
"description": "@alipay/spacex-shared",
5+
"main": "lib/index.js",
6+
"module": "esm/index.js",
7+
"typing": "types/index.d.ts",
8+
"files": [
9+
"lib",
10+
"esm",
11+
"types"
12+
],
13+
"repository": {
14+
"type": "git",
15+
"url": "git@code.alipay.com:winjo.gwj/SpaceX.git"
16+
},
17+
"keywords": [
18+
"kaitian AntCodespaces"
19+
],
20+
"scripts": {
21+
"start": "webpack-dev-server --env.entry=./src/distribution/app.tsx"
22+
},
23+
"publishConfig": {
24+
"registry": "https://registry.npm.alibaba-inc.com"
25+
},
26+
"dependencies": {
27+
"@alipay/spacex-cli": "0.0.1",
28+
"@alipay/spacex-core": "0.0.1"
29+
},
30+
"tnpm": {
31+
"mode": "yarn",
32+
"lockfile": "enable"
33+
},
34+
"devDependencies": {
35+
"@babel/plugin-proposal-class-properties": "^7.12.1",
36+
"@babel/plugin-proposal-decorators": "^7.12.1",
37+
"@babel/plugin-proposal-do-expressions": "^7.12.1",
38+
"@babel/plugin-proposal-export-default-from": "^7.12.1",
39+
"@babel/plugin-proposal-function-bind": "^7.12.1",
40+
"@babel/plugin-proposal-logical-assignment-operators": "^7.12.1",
41+
"@babel/plugin-proposal-pipeline-operator": "^7.12.1",
42+
"@babel/plugin-syntax-top-level-await": "^7.12.1",
43+
"@babel/plugin-transform-destructuring": "^7.12.1",
44+
"@babel/preset-env": "^7.12.7",
45+
"@babel/preset-react": "^7.12.7",
46+
"@babel/preset-typescript": "^7.12.7",
47+
"babel-loader": "^8.2.1",
48+
"copy-webpack-plugin": "^6.3.2",
49+
"css-loader": "^5.0.1",
50+
"file-loader": "^6.2.0",
51+
"fork-ts-checker-webpack-plugin": "^6.0.3",
52+
"friendly-errors-webpack-plugin": "^1.7.0",
53+
"html-webpack-plugin": "^4.5.0",
54+
"less-loader": "^7.1.0",
55+
"mini-css-extract-plugin": "^1.3.1",
56+
"raw-loader": "^4.0.2",
57+
"tsconfig-paths-webpack-plugin": "^3.3.0",
58+
"url-loader": "^4.1.1",
59+
"webpack": "^5.6.0",
60+
"webpack-merge": "^5.4.0"
61+
}
62+
}
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
// tslint:disable:no-var-requires
2+
const path = require('path');
3+
const HtmlWebpackPlugin = require('html-webpack-plugin');
4+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
5+
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
6+
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
7+
const CopyPlugin = require('copy-webpack-plugin');
8+
const webpack = require('webpack');
9+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
10+
const merge = require('webpack-merge');
11+
12+
const utils = require('./utils');
13+
14+
const tsConfigPath = path.join(__dirname, '../../../tsconfig.json');
15+
const port = process.env.IDE_FRONT_PORT || 8080;
16+
17+
console.log('front port', port);
18+
19+
const styleLoader = process.env.NODE_ENV === 'production'
20+
? MiniCssExtractPlugin.loader
21+
: require.resolve('style-loader');
22+
23+
/**
24+
* @param {{ webpackConfig: any, tsconfigPath?: string, env: string, outputPath: string, template: string }} config
25+
*/
26+
exports.createWebpackConfig = function(config) {
27+
const absOutputPath = path.resolve(config.outputPath || 'dist');
28+
29+
const baseConfig = {
30+
mode: config.env || 'development',
31+
devtool: 'inline-cheap-source-map',
32+
output: {
33+
path: absOutputPath,
34+
filename: '[name].js',
35+
chunkFilename: '[name].js',
36+
},
37+
resolve: {
38+
extensions: ['.ts', '.tsx', '.js', '.json', '.less'],
39+
plugins: [
40+
new TsconfigPathsPlugin({
41+
...(tsConfigPath ? { configFile: tsConfigPath } : {})
42+
})
43+
]
44+
},
45+
node: {
46+
net: "empty",
47+
child_process: "empty",
48+
path: "empty",
49+
url: false,
50+
fs: "empty",
51+
process: "mock"
52+
},
53+
optimization: {
54+
nodeEnv: config.env,
55+
},
56+
module: {
57+
// https://github.com/webpack/webpack/issues/196#issuecomment-397606728
58+
exprContextCritical: false,
59+
rules: [
60+
{
61+
test: /\.(js|mjs|jsx|ts|tsx)$/,
62+
use: [
63+
{
64+
loader: 'babel-loader',
65+
options: {
66+
babelrc: false,
67+
cacheDirectory: process.env.BABEL_CACHE !== 'none'
68+
? path.resolve('.cache/babel-loader')
69+
: false,
70+
presets: [
71+
[require('@babel/preset-env').default, {
72+
exclude: [
73+
'transform-typeof-symbol',
74+
'transform-unicode-regex',
75+
'transform-sticky-regex',
76+
'transform-new-target',
77+
'transform-modules-umd',
78+
'transform-modules-systemjs',
79+
'transform-modules-amd',
80+
'transform-literals',
81+
]
82+
}],
83+
[require('@babel/preset-react').default],
84+
[require('@babel/preset-typescript'), {
85+
allowNamespaces: true,
86+
}]
87+
],
88+
plugins: [
89+
require('@babel/plugin-syntax-top-level-await').default,
90+
[
91+
require('@babel/plugin-transform-destructuring').default,
92+
{ loose: false },
93+
],
94+
[
95+
require('@babel/plugin-proposal-decorators').default,
96+
{ legacy: true }
97+
],
98+
[
99+
require('@babel/plugin-proposal-class-properties').default,
100+
{ loose: true },
101+
],
102+
require('@babel/plugin-proposal-export-default-from').default,
103+
[
104+
require('@babel/plugin-proposal-pipeline-operator').default,
105+
{
106+
proposal: 'minimal',
107+
},
108+
],
109+
require('@babel/plugin-proposal-do-expressions').default,
110+
require('@babel/plugin-proposal-function-bind').default,
111+
require('@babel/plugin-proposal-logical-assignment-operators').default,
112+
]
113+
}
114+
}
115+
]
116+
},
117+
{
118+
test: /\.css$/,
119+
use: [styleLoader, 'css-loader'],
120+
},
121+
{
122+
test: /\.module.less$/,
123+
use: [
124+
styleLoader,
125+
{
126+
loader: 'css-loader',
127+
options: {
128+
importLoaders: 1,
129+
sourceMap: true,
130+
modules: true,
131+
localIdentName: '[local]___[hash:base64:5]'
132+
}
133+
},
134+
{
135+
loader: 'less-loader',
136+
options: {
137+
lessOptions: {
138+
javascriptEnabled: true,
139+
},
140+
}
141+
}
142+
]
143+
},
144+
{
145+
test: /^((?!\.module).)*less$/,
146+
use: [
147+
styleLoader,
148+
{
149+
loader: 'css-loader',
150+
options: {
151+
importLoaders: 1,
152+
}
153+
},
154+
{
155+
loader: 'less-loader',
156+
options: {
157+
lessOptions: {
158+
javascriptEnabled: true,
159+
},
160+
}
161+
}
162+
],
163+
},
164+
{
165+
test: /\.(png|jpe?g|gif|webp|ico)(\?.*)?$/,
166+
use: 'url-loader',
167+
options: {
168+
limit: config.inlineLimit || 10000,
169+
name: '[name].[ext]',
170+
// require 图片的时候不用加 .default
171+
esModule: false,
172+
fallback: {
173+
loader: 'file-loader',
174+
options: {
175+
name: '[name].[ext]',
176+
esModule: false,
177+
},
178+
}
179+
}
180+
},
181+
{
182+
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
183+
use: [{
184+
loader: 'file-loader',
185+
options: {
186+
name: '[name].[ext]',
187+
esModule: false,
188+
}
189+
}]
190+
},
191+
{
192+
test: /\.(txt|text|md)$/,
193+
use: 'raw-loader'
194+
}
195+
],
196+
},
197+
plugins: [
198+
new HtmlWebpackPlugin({
199+
template: config.template,
200+
}),
201+
new MiniCssExtractPlugin({
202+
filename: '[name].[chunkhash:8].css',
203+
chunkFilename: '[id].css',
204+
}),
205+
new webpack.DefinePlugin(config.define || {}),
206+
new FriendlyErrorsWebpackPlugin({
207+
compilationSuccessInfo: {
208+
messages: [`Your application is running here: http://localhost:${port}`],
209+
},
210+
onErrors: utils.createNotifierCallback(),
211+
clearConsole: true,
212+
}),
213+
new CopyPlugin(...(
214+
config.copy
215+
? config.copy.map((from) => ({
216+
from: path.resolve(from),
217+
to: absOutputPath,
218+
}))
219+
: []
220+
)),
221+
new ForkTsCheckerWebpackPlugin({
222+
checkSyntacticErrors: true,
223+
tsconfig: tsConfigPath,
224+
reportFiles: ['packages/**/*.{ts,tsx}']
225+
}),
226+
],
227+
}
228+
229+
return merge(baseConfig, config.webpackConfig)
230+
}

0 commit comments

Comments
 (0)