Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ssr): server file require add types intelligent code (#6149)
- Loading branch information
Showing
4 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export const CHUNK_NAME = 'server'; | ||
export const OUTPUT_SERVER_FILENAME = 'umi.server.js'; | ||
export const OUTPUT_SERVER_TYPE_FILENAME = 'umi.server.d.ts'; | ||
export const TMP_PLUGIN_DIR = 'core/ssr'; | ||
export const CLIENT_EXPORTS = 'clientExports'; |
32 changes: 32 additions & 0 deletions
32
packages/preset-built-in/src/plugins/features/ssr/serverTypePlugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { existsSync, readFileSync } from 'fs'; | ||
import { webpack } from '@umijs/types'; | ||
|
||
/** | ||
* generate assets when webpack bundler emit | ||
*/ | ||
export default class AssetWebpackPlugin { | ||
constructor( | ||
public assetPaths: { name: string; path?: string; content?: string }[], | ||
) { | ||
this.assetPaths = assetPaths; | ||
} | ||
apply(compiler: webpack.Compiler) { | ||
compiler.hooks.emit.tap('AssetWebpack', (compilation) => { | ||
this.assetPaths.forEach(({ name, path, content }) => { | ||
if (!name) { | ||
return; | ||
} | ||
const filePath = path || ''; | ||
const assetContent = existsSync(filePath) | ||
? readFileSync(filePath, 'utf-8') | ||
: content; | ||
if (assetContent) { | ||
compilation.assets[name] = { | ||
source: () => assetContent, | ||
size: () => assetContent.length, | ||
}; | ||
} | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters