Skip to content

Commit

Permalink
feat: umd support mako bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohuoni committed Apr 7, 2024
1 parent b1b4ca7 commit 26068a3
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 10 deletions.
14 changes: 14 additions & 0 deletions examples/mako/.fatherrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from '../../dist';
const path = require('path');

export default defineConfig({
umd: {
bundler: 'mako',
},
alias: {
'@': path.resolve(__dirname, './src'),
'hello-a': path.resolve(__dirname, './src/a.tsx'),
'hello-foo': path.resolve(__dirname, './src/foo.ts'),
},
platform: 'browser',
});
15 changes: 15 additions & 0 deletions examples/mako/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"scripts": {
"build": "OKAM=@alipay/umi-bundler-okam father build",
"build:no-clean": "father build --no-clean",
"dev": "father dev",
"dev:no-clean": "father dev --no-clean",
"doctor": "father doctor",
"version": "father version"
},
"dependencies": {
"father": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
15 changes: 15 additions & 0 deletions examples/mako/src/a.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
console.log('hello here');

// @ts-ignore
import React from 'react';
// @ts-ignore
import ReactDOM from 'react-dom';

function App({content}:{content:string}) {
// @ts-ignore
return <div>{content}</div>;
}

// @ts-ignore
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App content={'hello'}/>);
7 changes: 7 additions & 0 deletions examples/mako/src/content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Content {
say() {
return 'Hello father 3';
}
}

export default new Content().say();
1 change: 1 addition & 0 deletions examples/mako/src/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('foo here');
17 changes: 17 additions & 0 deletions examples/mako/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import content from '@/content';
import 'hello-a'
import 'hello-foo'
/*
import React from 'react';
import ReactDOM from 'react-dom';
// const content = 'Hello'
function App() {
return <div>{content}</div>;
}
// @ts-ignore
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
*/
console.log(content);
19 changes: 19 additions & 0 deletions examples/mako/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"skipLibCheck": true,
"target": "es2015",
"jsx": "react",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}
19 changes: 15 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions src/builder/bundle/mako.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import path from 'path';
import { tryPaths } from '@umijs/utils';
import { join, parse } from 'path';
import { getCachePath } from '../../utils';
import type { BundleConfigProvider, IBundleConfig } from '../config';
import { getBabelPresetReactOpts, getBundleTargets } from '../utils';
import { logStatus } from './utils';

const extensions = ['.js', '.jsx', '.ts', '.tsx', '.cjs', '.mjs'];

interface IBundleOpts {
cwd: string;
configProvider: BundleConfigProvider;
Expand All @@ -19,6 +23,10 @@ async function makoBundle(
require('@umijs/bundler-webpack/dist/requireHook');
// @ts-ignore
const { build, dev } = require(process.env.OKAM);
// mako need extension
const entry = tryPaths(
extensions.map((ext) => join(opts.cwd, `${config.entry}${ext}`)),
);
const options = {
cwd: opts.cwd,
config: {
Expand All @@ -43,10 +51,7 @@ async function makoBundle(
cacheDirectoryPath: getCachePath(),
},
entry: {
[path.parse(config.output.filename).name]: path.join(
opts.cwd,
config.entry,
),
[parse(config.output.filename).name]: entry,
},
babelPreset: [
require.resolve('@umijs/babel-preset-umi'),
Expand Down Expand Up @@ -81,7 +86,6 @@ async function makoBundle(
if (!isFirstCompile) logStatus(config);
},
};
console.log(options);

if (opts.watch) {
return await dev(options);
Expand Down

0 comments on commit 26068a3

Please sign in to comment.