Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor]: Document #618

Merged
merged 15 commits into from
Feb 25, 2021
29 changes: 0 additions & 29 deletions examples/with-rax-mpa/src/app.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions packages/plugin-rax-app/src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const fs = require('fs-extra');

module.exports = (api, { target, babelConfigOptions, progressOptions = {} }) => {
module.exports = (api, { target, babelConfigOptions, progressOptions = {}, isNode }) => {
const { context, onGetWebpackConfig } = api;
const { rootDir, command, userConfig } = context;

Expand Down Expand Up @@ -41,7 +41,7 @@ module.exports = (api, { target, babelConfigOptions, progressOptions = {} }) =>
.use('platform-loader')
.loader(require.resolve('rax-platform-loader'))
.options({
platform: target === 'ssr' ? 'node' : target,
platform: target === 'ssr' || isNode ? 'node' : target,
});
});

Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-rax-app/src/setDev.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ module.exports = function (api) {
// Remove outputDir when start devServer
const { outputDir = 'build' } = userConfig;
configs.forEach((config) => {
fs.emptyDirSync(path.resolve(rootDir, outputDir, config.name));
// Only empty build dir whick task configed name
if (config.name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

内置任务哪个链路不会设置 name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document 没设置,我设置下也行

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加一下注释

fs.emptyDirSync(path.resolve(rootDir, outputDir, config.name));
}
});

logWebpackConfig(configs);
Expand Down
21 changes: 10 additions & 11 deletions packages/plugin-rax-app/src/userConfig/inlineStyle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { resolve } = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { WEB, WEEX, DOCUMENT, SSR, KRAKEN, MINIAPP, WECHAT_MINIPROGRAM } = require('../constants');

const configPath = resolve(__dirname, '../');
Expand All @@ -17,9 +16,13 @@ const miniappStandardList = [
WECHAT_MINIPROGRAM,
];

const nodeStandardList = [
DOCUMENT,
SSR,
];

module.exports = (config, value, context) => {
const { taskName, command } = context;
const isDev = command === 'start';
const { taskName } = context;

const cssRule = config.module.rule('css');
const cssModuleRule = config.module.rule('css-module');
Expand All @@ -35,12 +38,9 @@ module.exports = (config, value, context) => {
const sassModuleRule = config.module.rule('scss-module');
setCSSRule(sassRule, context, value);
setCSSRule(sassModuleRule, context, value);
if ((webStandardList.includes(taskName) || miniappStandardList.includes(taskName)) && !value) {
config.plugin('MiniCssExtractPlugin')
.use(MiniCssExtractPlugin, [{
filename: isDev ? `${taskName}/[name].css` : '[name].css',
ignoreOrder: true,
}]);

if (value || inlineStandardList.includes(taskName) || nodeStandardList.includes(taskName)) {
config.plugins.delete('MiniCssExtractPlugin');
}
};

Expand All @@ -49,8 +49,7 @@ function setCSSRule(configRule, context, value) {
const isInlineStandard = inlineStandardList.includes(taskName);
const isWebStandard = webStandardList.includes(taskName);
const isMiniAppStandard = miniappStandardList.includes(taskName);
const isNodeStandard = taskName === DOCUMENT || taskName === SSR;

const isNodeStandard = nodeStandardList.includes(taskName);
// When taskName is weex or kraken, inlineStyle should be true
if (isInlineStandard) {
value = true;
Expand Down
13 changes: 8 additions & 5 deletions packages/plugin-rax-kraken/src/setEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ const fs = require('fs-extra');
const path = require('path');

module.exports = (config, context) => {
const { rootDir } = context;
// SPA
const appEntry = moduleResolve(formatPath(path.join(rootDir, './src/app')));
const entryConfig = config.entry('index');
const { rootDir, userConfig: { kraken = {} } } = context;

entryConfig.add(appEntry);
if (!kraken.mpa) {
// SPA
const appEntry = moduleResolve(formatPath(path.join(rootDir, './src/app')));
const entryConfig = config.entry('index');

entryConfig.add(appEntry);
}
};

function moduleResolve(filePath) {
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-rax-web/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'chalk' {
export const hex: any;
export const underline: any;
export const red: any;
}
13 changes: 7 additions & 6 deletions packages/plugin-rax-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
"rax": "^1.0.0"
},
"dependencies": {
"@builder/app-helpers": "^2.1.0",
"@builder/mpa-config": "^3.0.0",
"chalk": "^4.1.0",
"cheerio": "1.0.0-rc.3",
"error-stack-tracey": "^0.1.4",
"fs-extra": "^9.0.1",
"html-minifier": "^4.0.0",
"klaw-sync": "^6.0.0",
"node-hot-loader": "^1.21.0",
"qs": "^6.9.4",
"rax-server-renderer": "^1.2.0",
"webpack-sources": "^2.0.0",
"webpack": "^4.0.0",
"@builder/app-helpers": "^2.1.0",
"react-dev-utils": "^10.0.0",
"chalk": "^4.1.0",
"html-minifier": "^4.0.0",
"cheerio": "1.0.0-rc.3"
"webpack": "^4.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个依赖应该是可以移除的,底层 build-scripts 已经依赖了,如果 plugin-rax-web 有用到内置 webpack 插件的,可以从 context 上取

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已删除,是之前的依赖

"webpack-sources": "^2.0.0"
}
}
40 changes: 0 additions & 40 deletions packages/plugin-rax-web/src/DocumentPlugin/builtInLoader.ts

This file was deleted.

68 changes: 0 additions & 68 deletions packages/plugin-rax-web/src/DocumentPlugin/customLoader.ts

This file was deleted.

Loading