Skip to content

Commit f65e215

Browse files
maoxiaokelianmin
andauthored
Release: build-plugin-component 1.3.0 (#93)
* feat: 🎸 custom portal moduels exposed mothods to build-plugin-miniapp-preview ✅ Closes: #66, #53 * fix: 🐛 can not gen device.js when run start * chore: 🤖 version * Feat/optimize component doc (#94) ✅ Closes: #86 * chore: 🤖 change version to 1.3.0 Co-authored-by: 山河 <406400939@qq.com>
1 parent c0c2fd2 commit f65e215

File tree

18 files changed

+209
-243
lines changed

18 files changed

+209
-243
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ packages/*/es/
1919
.vscode-test
2020

2121
**/.ice/
22+
.idea/
2223

2324
**/package-lock.json
2425
**/build

packages/build-plugin-component/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "build-plugin-component",
3-
"version": "1.2.2",
3+
"version": "1.3.0",
44
"description": "build plugin for component development",
55
"main": "src/index.js",
66
"scripts": {

packages/build-plugin-component/src/compiler/babel.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const getBabelConfig = ({ target, componentLibs, rootDir, babelPlugins, babelOpt
3131
}
3232
// generate babel-plugin-import config
3333
const plugins = [];
34-
componentLibs.forEach(libraryName => {
34+
componentLibs.forEach((libraryName) => {
3535
// check es folder if target is es
3636
const pluginOption = {
3737
libraryName,
@@ -52,7 +52,7 @@ const getBabelConfig = ({ target, componentLibs, rootDir, babelPlugins, babelOpt
5252
babelConfig.plugins = babelConfig.plugins.concat(plugins);
5353
if (alias) {
5454
const aliasRelative = {};
55-
Object.keys(alias).forEach(aliasKey => {
55+
Object.keys(alias).forEach((aliasKey) => {
5656
aliasRelative[aliasKey] = alias[aliasKey].startsWith('./') ? alias[aliasKey] : `./${alias[aliasKey]}`;
5757
});
5858
babelConfig.plugins = babelConfig.plugins.concat([[
@@ -84,11 +84,11 @@ module.exports = function babelCompiler(
8484
const filesPath = glob.sync('**/*.*', { cwd: srcPath, ignore: ['node_modules/**', '*.d.ts'] });
8585
// traverse to compile the js files
8686
const compileInfo = [];
87-
compileTargets.forEach(target => {
87+
compileTargets.forEach((target) => {
8888
const destPath = path.join(rootDir, target);
8989
// clear dir
9090
fs.emptyDirSync(destPath);
91-
filesPath.forEach(filePath => {
91+
filesPath.forEach((filePath) => {
9292
const sourceFile = path.join(srcPath, filePath);
9393
if (!REG_JS.test(filePath) || REG_D_TS.test(filePath)) {
9494
// copy file if it does not match REG_JS

packages/build-plugin-component/src/configs/rax/getDemoConfig.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
33
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
44
const { hmrClient } = require('rax-compile-config');
55
const getBaseWebpack = require('./getBaseWebpack');
6-
const generateRaxDemo = require('../../utils/generateRaxDemo');
76
const setCSSRule = require('../../utils/setCSSRule');
7+
const { getRaxDemoEntryJs } = require('../../utils/handlePaths');
88

99
module.exports = (context, options) => {
1010
const { command, rootDir } = context;
11-
const { demos, entries } = options;
11+
const { demos, entries, inlineStyle = true } = options;
1212
const config = getBaseWebpack(context, { ...options, name: 'demo' });
13-
const portalPath = generateRaxDemo(demos, context);
13+
const portalPath = getRaxDemoEntryJs(rootDir);
1414
if (command === 'start') {
1515
config
1616
.entry('portal')
@@ -23,7 +23,7 @@ module.exports = (context, options) => {
2323
config.output.filename('[name].js');
2424
config.output.publicPath('./');
2525
config.output.path(path.join(rootDir, 'build'));
26-
setCSSRule(config, command !== 'start');
26+
setCSSRule(config, inlineStyle);
2727
if (command === 'start') {
2828
config.output.publicPath('/demo');
2929
} else {
@@ -38,6 +38,8 @@ module.exports = (context, options) => {
3838
filename: `demo/${entryKey}.html`,
3939
chunks: [entryKey],
4040
jsPath: `./${entryKey}.js`,
41+
cssPath: `./${entryKey}.css`,
42+
inlineStyle,
4143
template: path.resolve(__dirname, '../../template/raxDemo.html'),
4244
},
4345
]);

packages/build-plugin-component/src/configs/rax/getDistConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = (context, options) => {
2727
]);
2828
// 输出到 dist 目录
2929
config.output.path(path.join(rootDir, 'dist'));
30+
3031
setCSSRule(config, options.inlineStyle);
3132
config.plugin('minicss')
3233
.use(MiniCssExtractPlugin, [{

packages/build-plugin-component/src/configs/rax/miniapp/getBase.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const parseTarget = (target) => (target === MINIAPP ? 'ali-miniapp' : target);
1010
module.exports = (context, target, options = {}, onGetWebpackConfig) => {
1111
const { rootDir, command } = context;
1212
const { distDir = '' } = options[target] || {};
13+
1314
const outputPath = getOutputPath(context, { target, distDir });
1415
const config = getWebpackBase(context, {
1516
disableRegenerator: true,

packages/build-plugin-component/src/rax.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ const devCompileLog = require('./utils/raxDevCompileLog');
2020
const buildCompileLog = require('./utils/raxBuildCompileLog');
2121
const modifyPkgHomePage = require('./utils/modifyPkgHomePage');
2222
const getDemoConfig = require('./configs/rax/getDemoConfig');
23+
const getReadme = require('./utils/getReadme');
24+
const generateRaxDemo = require('./utils/generateRaxDemo');
25+
const { setModulesInfo } = require('./utils/getPortalModules');
2326

24-
module.exports = ({ registerTask, registerUserConfig, context, onHook, registerCliOption, onGetWebpackConfig, onGetJestConfig, modifyUserConfig, log }) => {
27+
module.exports = ({ registerTask, registerUserConfig, context, onHook, registerCliOption, onGetWebpackConfig, onGetJestConfig, modifyUserConfig, log, registerMethod, setValue }) => {
2528
const { rootDir, userConfig, command, pkg, commandArgs } = context;
2629
const { plugins, targets, disableUMD, inlineStyle = true, ...compileOptions } = userConfig;
2730
if (!(targets && targets.length)) {
@@ -37,6 +40,12 @@ module.exports = ({ registerTask, registerUserConfig, context, onHook, registerC
3740
registerUserConfig(defaultUserConfig.concat(raxUserConfig));
3841
// disable demo when watch dist
3942

43+
registerMethod('pluginComponentGetDemoDir', getDemoDir);
44+
registerMethod('pluginComponentGetDemos', getDemos);
45+
registerMethod('pluginComponentGetReadme', getReadme);
46+
registerMethod('pluginComponentSetPortalModules', setModulesInfo);
47+
setValue('pluginComponentDir', __dirname);
48+
4049
let entries = {};
4150
let serverBundles = {};
4251
let demos = [];
@@ -76,7 +85,7 @@ module.exports = ({ registerTask, registerUserConfig, context, onHook, registerC
7685
if (raxBundles) {
7786
entries = raxBundles.entries;
7887
serverBundles = raxBundles.serverBundles;
79-
const demoConfig = getDemoConfig(context, { ...compileOptions, entries, demos });
88+
const demoConfig = getDemoConfig(context, { ...compileOptions, entries, demos, inlineStyle });
8089
registerTask('component-demo', demoConfig);
8190
}
8291
}
@@ -108,7 +117,7 @@ module.exports = ({ registerTask, registerUserConfig, context, onHook, registerC
108117
fse.removeSync(path.join(rootDir, 'build'));
109118
fse.removeSync(path.join(rootDir, 'es'));
110119

111-
targets.forEach(target => {
120+
targets.forEach((target) => {
112121
const options = { ...userConfig, target, inlineStyle };
113122
if (target === WEB) {
114123
registerTask(`component-build-${target}`, getDistConfig(context, options));
@@ -140,16 +149,22 @@ module.exports = ({ registerTask, registerUserConfig, context, onHook, registerC
140149
});
141150
}
142151

152+
onHook(`before.${command}.run`, async () => {
153+
await generateRaxDemo(demos, context);
154+
});
155+
143156
onHook('after.build.compile', async (args) => {
144157
buildCompileLog(args, targets, rootDir, userConfig);
145158
if (!skipDemo) {
146159
await modifyPkgHomePage(pkg, rootDir);
147160
}
148161
});
162+
149163
onHook('after.start.compile', async (args) => {
150164
const devUrl = args.url;
151165
devCompileLog(args, devUrl, targets, entries, rootDir, { ...userConfig, watchDist });
152166
});
167+
153168
if (command === 'test') {
154169
// jest config
155170
onGetJestConfig((jestConfig) => {
@@ -177,4 +192,4 @@ function addMiniappTargetParam(target, originalConfig = {}) {
177192
break;
178193
}
179194
originalConfig.mode = 'watch';
180-
}
195+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { createElement } from 'rax';
2+
3+
const Device = ({ children }) => (
4+
<div className={'device-view'}>
5+
<svg className="device-md-bar" viewBox="0 0 1384.3 40.3">
6+
<path className="st0" d="M1343 5l18.8 32.3c.8 1.3 2.7 1.3 3.5 0L1384 5c.8-1.3-.2-3-1.7-3h-37.6c-1.5 0-2.5 1.7-1.7 3z" />
7+
<circle className="st0" cx="1299" cy="20.2" r="20" />
8+
<path
9+
className="st0"
10+
d="M1213 1.2h30c2.2 0 4 1.8 4 4v30c0 2.2-1.8 4-4 4h-30c-2.2 0-4-1.8-4-4v-30c0-2.3 1.8-4 4-4zM16 4.2h64c8.8 0 16 7.2 16 16s-7.2 16-16 16H16c-8.8 0-16-7.2-16-16s7.2-16 16-16z"
11+
/>
12+
</svg>
13+
14+
<svg className="device-ios-notch" viewBox="0 0 219 31">
15+
<path d="M0 1V0h219v1a5 5 0 0 0-5 5v3c0 12.15-9.85 22-22 22H27C14.85 31 5 21.15 5 9V6a5 5 0 0 0-5-5z" fillRule="evenodd" />
16+
</svg>
17+
18+
<div className="device-view-inner">{children}</div>
19+
</div>
20+
);
21+
22+
export default Device;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"builtInModules_blacklist": ["core-js"]
3+
}

packages/build-plugin-component/src/template/raxDemo.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, minimum-scale=1, user-scalable=no">
66
<title>Rax Component Demo</title>
7+
<% if (!htmlWebpackPlugin.options.inlineStyle) { %>
8+
<link rel="stylesheet" href="<%= htmlWebpackPlugin.options.cssPath %>"></link>
9+
<% } %>
710
</head>
811
<body style="padding: 0;margin: 0">
912
<script type="text/javascript" src="<%= htmlWebpackPlugin.options.jsPath %>"></script>

0 commit comments

Comments
 (0)