Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

feat: 支持运行时插件 #988

Merged
merged 2 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: fix runtime plugin path
  • Loading branch information
yesmeck committed May 26, 2020
commit 27b54cf3097a92fafab94fc058a723ab737eefec
3 changes: 2 additions & 1 deletion packages/remax-cli/src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Options, Plugin, Meta, HostComponent, Platform } from '@remax/types';
import { merge } from 'lodash';
import Config from 'webpack-chain';
import { RuleConfig } from './build/webpack/config/css';
import winPath from '@remax/macro/lib/utils/winPath';

export default class API {
public plugins: Plugin[] = [];
Expand Down Expand Up @@ -112,7 +113,7 @@ export default class API {
return this.plugins
.map(plugin => {
if (typeof plugin.registerRuntimePlugin === 'function') {
return plugin.registerRuntimePlugin();
return winPath(plugin.registerRuntimePlugin());
}
})
.filter(Boolean);
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export default {
onAppConfig(config) {
onAppConfig({ config }) {
return config;
},
onPageConfig(config) {
onPageConfig({ config }) {
return config;
},
};
2 changes: 2 additions & 0 deletions packages/remax-cli/src/build/utils/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface Alias {
export default (options: Options, target: Platform) => {
const config: Alias = {
'@': path.resolve(options.cwd, options.rootDir),
// 配合 webpack-virtual-modules
'@remax/runtime-plugin': path.join(options.cwd, 'node_modules/@remax/runtime-plugin.js'),
};

if (target !== Platform.web) {
Expand Down
5 changes: 1 addition & 4 deletions packages/remax-cli/src/build/webpack/config.mini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ export default function webpackConfig(api: API, options: Options, target: Platfo
.loader(require.resolve('file-loader'));

const pluginTemplate = fs.readFileSync(path.resolve(__dirname, '../../../template/plugin.js.ejs'), 'utf-8');
const pluginPath = path.join(
path.resolve(path.dirname(require.resolve('@remax/runtime')), '..'),
'node_modules/@remax/runtime-plugin.js'
);
const pluginPath = winPath('node_modules/@remax/runtime-plugin.js');
const virtualModules = new VirtualModulesPlugin({
[pluginPath]: ejs.render(pluginTemplate, {
pluginFiles: api.getRuntimePluginFiles(),
Expand Down
8 changes: 4 additions & 4 deletions packages/remax-runtime/src/PluginDriver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface Plugin {
onAppConfig?: (config: any) => any;
onPageConfig?: (config: any) => any;
onAppConfig?: ({ config }: { config: any }) => any;
onPageConfig?: ({ config }: { config: any }) => any;
}

export default class PluginDriver {
Expand All @@ -13,7 +13,7 @@ export default class PluginDriver {
onAppConfig(config: any) {
return this.plugins.reduce((acc, plugin) => {
if (typeof plugin.onAppConfig === 'function') {
acc = plugin.onAppConfig(config);
acc = plugin.onAppConfig({ config });
}
return acc;
}, config);
Expand All @@ -22,7 +22,7 @@ export default class PluginDriver {
onPageConfig(config: any) {
return this.plugins.reduce((acc, plugin) => {
if (typeof plugin.onPageConfig === 'function') {
acc = plugin.onPageConfig(config);
acc = plugin.onPageConfig({ config });
}
return acc;
}, config);
Expand Down
8 changes: 4 additions & 4 deletions packages/remax-runtime/src/__tests__/PluginDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ describe('PluginDriver', () => {
it('onAppConfig', () => {
const pluginDriver = new PluginDriver([
{
onAppConfig(config) {
onAppConfig({ config }) {
config.foo = 1;
return config;
},
},
{
onAppConfig(config) {
onAppConfig({ config }) {
config.bar = 1;
return config;
},
Expand All @@ -23,13 +23,13 @@ describe('PluginDriver', () => {
it('onPageConfig', () => {
const pluginDriver = new PluginDriver([
{
onPageConfig(config) {
onPageConfig({ config }) {
config.foo = 1;
return config;
},
},
{
onPageConfig(config) {
onPageConfig({ config }) {
config.bar = 1;
return config;
},
Expand Down
2 changes: 1 addition & 1 deletion packages/remax-runtime/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export { default as render } from './render';
export { default as PluginDriver } from './PluginDriver';
export { default as createAppConfig } from './createAppConfig';
export { default as createPageConfig } from './createPageConfig';
export { default as createHostComponent } from './createHostComponent';
export { default as createNativeComponent } from './createNativeComponent';
export { default as PluginDriver } from './PluginDriver';
export * from './hooks';

import { ReactReconcilerInst } from './render';
Expand Down