Skip to content

Commit 612139d

Browse files
maoxiaokeduwenbin0316mskj-duwenbin
authored
release/component-1.7.0 (#213)
* fix: dts file generate error at windows (#173) * feat: 🎸 support define * feat/https (#218) Co-authored-by: duwenbin0316 <31891889+duwenbin0316@users.noreply.github.com> Co-authored-by: mskj-duwenbin <duwenbin@mskj.com>
1 parent b1bc5b6 commit 612139d

File tree

10 files changed

+64
-11
lines changed

10 files changed

+64
-11
lines changed

packages/build-plugin-component/CHANGELOG.md

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

3+
## 1.7.0
4+
5+
- [feat] support `https` cli option
6+
- [feat] support `define` user config option
7+
- [fix] generate .d.ts files for win32
8+
39
## 1.6.6
410

511
- [hotfix] 修复 inlineStyle 默认为 true 这一行为逻辑的 break change ([#214](https://github.com/ice-lab/iceworks-cli/issues/214))

packages/build-plugin-component/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "build-plugin-component",
3-
"version": "1.6.6",
3+
"version": "1.7.0",
44
"description": "build plugin for component development",
55
"main": "src/index.js",
66
"scripts": {
@@ -28,6 +28,7 @@
2828
"@babel/types": "^7.7.2",
2929
"babel-plugin-import": "^1.12.2",
3030
"babel-plugin-module-resolver": "^4.0.0",
31+
"babel-plugin-transform-define": "^2.0.0",
3132
"build-scripts-config": "^0.1.0",
3233
"camelcase": "^6.2.0",
3334
"case-sensitive-paths-webpack-plugin": "^2.3.0",

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,16 @@ module.exports = function babelCompiler(
8383
type,
8484
) {
8585
const { rootDir, pkg } = context;
86-
const { compilerOptions = {}, babelPlugins = [], babelOptions = [], alias, subComponents } = userOptions;
86+
const { compilerOptions = {}, babelOptions = [], alias, subComponents, define } = userOptions;
87+
const { babelPlugins = [] } = userOptions;
88+
89+
if (define) {
90+
babelPlugins.push([
91+
require.resolve('babel-plugin-transform-define'),
92+
define,
93+
]);
94+
}
95+
8796
// generate DTS for ts files, default is true
8897
const { declaration = true } = compilerOptions;
8998
const componentLibs = analyzePackage(pkg, basicComponents);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const path = require('path');
77
const fse = require('fs-extra');
88
const ts = require('typescript');
99
const { REG_TS } = require('../configs/reg');
10+
const formatPathForWin = require('../utils/formatPathForWin');
1011

1112
// compile options
1213
const options = {
@@ -40,7 +41,7 @@ module.exports = function dtsCompiler(compileInfo, log = console) {
4041
const program = ts.createProgram(needCompileList.map(({ sourceFile }) => sourceFile), options, host);
4142
const emitResult = program.emit();
4243
if (emitResult.diagnostics && emitResult.diagnostics.length > 0) {
43-
emitResult.diagnostics.forEach(diagnostic => {
44+
emitResult.diagnostics.forEach((diagnostic) => {
4445
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
4546
if (diagnostic.file) {
4647
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
@@ -52,7 +53,9 @@ module.exports = function dtsCompiler(compileInfo, log = console) {
5253
}
5354

5455
needCompileList.forEach(({ targetPath, fileNamesDTS }) => {
55-
const content = createdFiles[fileNamesDTS];
56+
const content = createdFiles[
57+
formatPathForWin(fileNamesDTS)
58+
];
5659
// write file
5760
if (content) {
5861
fse.ensureDirSync(path.dirname(targetPath));

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const TimeFixPlugin = require('time-fix-plugin');
1010

1111
module.exports = (context, options) => {
1212
const { rootDir, command, pkg, webpack } = context;
13-
const { isES6, target, name, inlineStyle = true } = options || {};
13+
const { isES6, target, name, inlineStyle = true, https } = options || {};
1414
const config = new Chain();
1515

1616
const babelConfig = getBabelConfig({
@@ -101,6 +101,8 @@ module.exports = (context, options) => {
101101
if (command === 'start') {
102102
config.mode('development');
103103
config.devtool('inline-module-source-map');
104+
105+
config.devServer.https(Boolean(https));
104106
} else if (command === 'build') {
105107
config.mode('production');
106108
// support production sourcemap

packages/build-plugin-component/src/configs/react/dev.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const setAssetsPath = require('../../utils/setAssetsPath');
22

3-
module.exports = (config) => {
3+
module.exports = (config, options) => {
4+
const { https } = options;
45
setAssetsPath(config, { js: 'js', css: 'css' });
56
// config loglevel
67
config.merge({
@@ -12,4 +13,6 @@ module.exports = (config) => {
1213
.hot(true)
1314
.disableHostCheck(true)
1415
.clientLogLevel('silent');
16+
17+
config.devServer.https(Boolean(https));
1518
};

packages/build-plugin-component/src/configs/react/userConfig.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,8 @@ module.exports = [
6464
name: 'htmlInjection',
6565
validation: 'object',
6666
},
67+
{
68+
name: 'define',
69+
validation: 'object',
70+
},
6771
];

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = ({
4848
console.log();
4949
process.exit(1);
5050
}
51-
const { skipDemo } = commandArgs;
51+
const { skipDemo, https } = commandArgs;
5252
const watchDist = commandArgs.watchDist || userConfig.watchDist;
5353
const isRuntimeMiniapp = targets.includes(MINIAPP) && miniapp && miniapp.buildType === 'runtime';
5454

@@ -70,7 +70,7 @@ module.exports = ({
7070
let demos = [];
7171

7272
// register cli options
73-
const cliOptions = ['watch-dist', '--skip-demo'];
73+
const cliOptions = ['watch-dist', '--skip-demo', 'https'];
7474
registerCliOption(
7575
cliOptions.map((name) => ({
7676
name,
@@ -120,7 +120,12 @@ module.exports = ({
120120
// plugins depend on task names, change task name rule will cause break change.
121121
if (command === 'start' && !watchDist) {
122122
targets.forEach((target) => {
123-
const options = { ...compileOptions, target, inlineStyle };
123+
const options = {
124+
...compileOptions,
125+
target,
126+
inlineStyle,
127+
https,
128+
};
124129
if ([WEB, WEEX, NODE, KRAKEN].includes(target)) {
125130
// eslint-disable-next-line
126131
const configDev = require(`./configs/rax/${target}/dev`);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = (
2828
const { command, rootDir, pkg, commandArgs, userConfig } = context;
2929
const { plugins, ...compileOptions } = userConfig;
3030
const { library, demoTemplate = 'template-component-demo', basicComponents = [] } = compileOptions;
31+
const { https } = commandArgs;
3132

3233
// config htmlInjection for once
3334
if (userConfig.htmlInjection) {
@@ -47,9 +48,11 @@ module.exports = (
4748
registerTask(taskName, webpackConfig);
4849
const outputDir = path.join(rootDir, 'node_modules', '_component_demo');
4950
fs.ensureDirSync(outputDir);
51+
5052
const params = {
5153
rootDir,
5254
pkg,
55+
https,
5356
};
5457

5558
const generateDemoEntry = () => {
@@ -142,7 +145,7 @@ module.exports = (
142145
}
143146

144147
// register cli options
145-
const cliOptions = ['watch', 'skip-demo', 'watch-dist'];
148+
const cliOptions = ['watch', 'skip-demo', 'watch-dist', 'https'];
146149
registerCliOption(cliOptions.map((name) => ({
147150
name,
148151
commands: ['start', 'build'],

packages/build-plugin-component/src/utils/getUMDWebpack.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { defaultDynamicImportLibraries } = require('../compiler/depAnalyze');
66
module.exports = ({ context, compileOptions, extNames, hasMain }) => {
77
const mode = 'production';
88
const config = getWebpackConfig(mode);
9-
const { rootDir } = context;
9+
const { rootDir, webpack } = context;
1010
const {
1111
// dist minify
1212
minify,
@@ -46,6 +46,7 @@ module.exports = ({ context, compileOptions, extNames, hasMain }) => {
4646
},
4747
},
4848
basicComponents = [],
49+
define,
4950
} = compileOptions;
5051
const { jsExt, styleExt } = extNames;
5152
// file name
@@ -144,5 +145,21 @@ module.exports = ({ context, compileOptions, extNames, hasMain }) => {
144145
config.optimization.minimize(minify);
145146
}
146147

148+
if (define) {
149+
const defineVariables = {};
150+
Object.keys(define).forEach((defineKey) => {
151+
defineVariables[defineKey] = JSON.stringify(define[defineKey]);
152+
});
153+
154+
if (config.plugins.get('DefinePlugin')) {
155+
config
156+
.plugin('DefinePlugin')
157+
.tap((args) => [Object.assign(...args, defineVariables)]);
158+
} else {
159+
config.plugin('DefinePlugin')
160+
.use(webpack.DefinePlugin, [defineVariables]);
161+
}
162+
}
163+
147164
return config;
148165
};

0 commit comments

Comments
 (0)