Skip to content

Commit bbec219

Browse files
committed
feat(build-plugin-alt): 支持 plugin 开发时 lcMeta 的注入,生成 lcMeta 的逻辑默认开启
1 parent e8c923a commit bbec219

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

packages/build-plugin-alt/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.0.6
4+
5+
- `feat` 支持 plugin 开发时 lcMeta 的注入,生成 lcMeta 的逻辑默认开启
6+
37
## 1.0.5
48

59
- `feat` 本地调试兼容性依赖 lowcode-engine

packages/build-plugin-alt/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alilc/build-plugin-alt",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "build-scripts plugin template for developers",
55
"main": "lib/index.js",
66
"files": [

packages/build-plugin-alt/src/baseConfig.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import * as path from 'path';
66
interface IOptions extends Partial<PluginContext> {
77
entry: object;
88
type: string;
9+
mainFile: string;
10+
generateMeta?: boolean;
911
}
1012

11-
export default (config: WebpackChain, { rootDir, entry, type }: IOptions) => {
13+
export default (config: WebpackChain, { rootDir, entry, type, pkg, mainFile, generateMeta }: IOptions) => {
1214
config.target('web');
1315
config.context(rootDir);
1416
config.merge({
@@ -58,4 +60,22 @@ export default (config: WebpackChain, { rootDir, entry, type }: IOptions) => {
5860
.add(/node_modules/)
5961
.end()
6062
.type('javascript/auto');
63+
64+
if (type === 'plugin' && generateMeta && pkg.lcMeta) {
65+
['tsx', 'jsx'].forEach((ruleName) => {
66+
config.module.rule(ruleName).use('babel-loader').tap((options) => {
67+
return {
68+
...options,
69+
plugins: [
70+
...options.plugins,
71+
[require.resolve('./babelPluginMeta'), {
72+
filename: mainFile,
73+
meta: pkg.lcMeta,
74+
}],
75+
]
76+
}
77+
})
78+
})
79+
}
80+
6181
}

packages/build-plugin-alt/src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import WebpackChain from 'webpack-chain';
44
import * as path from 'path';
55
import babelCompiler from 'build-plugin-component/src/compiler/babel';
66
import openBrowser from 'react-dev-utils/openBrowser';
7+
import { existsSync } from 'fs-extra';
78
import baseConfig from './baseConfig';
89
import devConfig from './devConfig';
910
import builtinConfig from './builtinConfig';
@@ -19,8 +20,13 @@ interface IOpitons {
1920
}
2021

2122
const plugin: IPlugin = ({ context, registerTask, onGetWebpackConfig, onHook, log }, options) => {
22-
const { type, inject, openUrl, generateMeta = false } = options as unknown as IOpitons;
23+
const { type, inject, openUrl, generateMeta = true } = options as unknown as IOpitons;
2324
const { command, rootDir, userConfig, pkg } = context;
25+
const mainFilePrefix = path.join(rootDir, 'src', (pkg.main as string).replace(/lib\/(.*).js/, "$1"));
26+
let mainFile = `${mainFilePrefix}.tsx`;
27+
if (!existsSync(mainFile)) {
28+
mainFile = `${mainFilePrefix}.jsx`;
29+
}
2430
if (command === 'start') {
2531
if (type !== 'component') {
2632
const webpackConfig = getWebpackConfig('development') as WebpackChain;
@@ -30,6 +36,9 @@ const plugin: IPlugin = ({ context, registerTask, onGetWebpackConfig, onHook, lo
3036
baseConfig(config, {
3137
rootDir,
3238
type,
39+
pkg,
40+
mainFile,
41+
generateMeta,
3342
entry: {
3443
index: path.join(__dirname, `./entry/${type}.js`),
3544
preview: path.join(__dirname, './entry/preview.js'),
@@ -50,6 +59,7 @@ const plugin: IPlugin = ({ context, registerTask, onGetWebpackConfig, onHook, lo
5059
baseConfig(config, {
5160
rootDir,
5261
type,
62+
mainFile,
5363
entry: {
5464
component: path.join(__dirname, './builtIn/component.js'),
5565
}
@@ -81,7 +91,6 @@ const plugin: IPlugin = ({ context, registerTask, onGetWebpackConfig, onHook, lo
8191
onHook('before.build.load', () => {
8292
const babelPlugins = [];
8393
if (type === 'plugin' && generateMeta && pkg.lcMeta) {
84-
const mainFile = path.join(rootDir, 'src', `${(pkg.main as string).replace(/lib\/(.*).js/, "$1")}.tsx`);
8594
babelPlugins.push([require.resolve('./babelPluginMeta'), {
8695
filename: mainFile,
8796
meta: pkg.lcMeta,

0 commit comments

Comments
 (0)