feat: 🎸 globalStyle 支持定制样式文件的后缀名

This commit is contained in:
牧毅 2020-08-21 11:04:06 +08:00
parent 166c70b94c
commit e78dae09a6

View File

@ -9,7 +9,18 @@ import {
IProjectInfo, IProjectInfo,
} from '../../../../../types'; } from '../../../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => { export type GlobalStylePluginConfig = {
fileType: string;
};
const pluginFactory: BuilderComponentPluginFactory<GlobalStylePluginConfig> = (
config?: Partial<GlobalStylePluginConfig>,
) => {
const cfg: GlobalStylePluginConfig = {
fileType: FileType.SCSS,
...config,
};
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -19,7 +30,7 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
next.chunks.push({ next.chunks.push({
type: ChunkType.STRING, type: ChunkType.STRING,
fileType: FileType.SCSS, // TODO: 样式文件的类型定制化? fileType: cfg.fileType,
name: COMMON_CHUNK_NAME.StyleDepsImport, name: COMMON_CHUNK_NAME.StyleDepsImport,
content: ``, content: ``,
linkAfter: [], linkAfter: [],
@ -27,7 +38,7 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
next.chunks.push({ next.chunks.push({
type: ChunkType.STRING, type: ChunkType.STRING,
fileType: FileType.SCSS, fileType: cfg.fileType,
name: COMMON_CHUNK_NAME.StyleCssContent, name: COMMON_CHUNK_NAME.StyleCssContent,
content: ` content: `
body { body {
@ -39,7 +50,7 @@ body {
next.chunks.push({ next.chunks.push({
type: ChunkType.STRING, type: ChunkType.STRING,
fileType: FileType.SCSS, fileType: cfg.fileType,
name: COMMON_CHUNK_NAME.StyleCssContent, name: COMMON_CHUNK_NAME.StyleCssContent,
content: ir.css || '', content: ir.css || '',
linkAfter: [COMMON_CHUNK_NAME.StyleDepsImport], linkAfter: [COMMON_CHUNK_NAME.StyleDepsImport],