This commit is contained in:
万纯 2021-03-04 19:48:49 +08:00
commit 9c9c463e5a
5 changed files with 36 additions and 4 deletions

View File

@ -28,6 +28,7 @@ export default function () {
require.resolve('./plugins/features/extraBabelPresets'),
require.resolve('./plugins/features/extraPostCSSPlugins'),
require.resolve('./plugins/features/html'),
require.resolve('./plugins/features/globalCSS'),
require.resolve('./plugins/features/inlineLimit'),
require.resolve('./plugins/features/lessLoader'),
require.resolve('./plugins/features/mountElementId'),

View File

@ -2,9 +2,10 @@ import {
winPath
} from '@umijs/utils';
function getBabelOpts({
function getBableOpts({
cwd,
targets,
config,
presetOpts
}) {
const presets = [
@ -19,7 +20,8 @@ function getBabelOpts({
},
modules: false
}
]
],
...(config.extraBabelPresets || [])
];
const plugins = [
require('@babel/plugin-proposal-export-default-from').default,
@ -45,7 +47,8 @@ function getBabelOpts({
importOpts.libraryName
])
: []),
require.resolve('@vue/babel-plugin-jsx')
require.resolve('@vue/babel-plugin-jsx'),
...(config.extraBabelPresets || [])
];
return {
babelrc: false,
@ -62,6 +65,7 @@ function getBabelOpts({
export default async ({
cwd,
config,
modifyBabelOpts,
modifyBabelPresetOpts,
targets
@ -72,8 +76,9 @@ export default async ({
if (modifyBabelPresetOpts) {
presetOpts = await modifyBabelPresetOpts(presetOpts);
}
let babelOpts = getBabelOpts({
let babelOpts = getBableOpts({
cwd,
config,
presetOpts,
targets
});

View File

@ -157,6 +157,7 @@ export default async function getConfig({
const { targets, browserslist } = getTargetsAndBrowsersList({ config });
const babelOpts = await getBableOpts({
cwd,
config,
modifyBabelOpts,
modifyBabelPresetOpts,
targets

View File

@ -0,0 +1,25 @@
import { relative, join } from 'path';
import { existsSync } from 'fs';
export default (api) => {
const {
paths,
utils: { winPath }
} = api;
const { absSrcPath = '', absTmpPath = '' } = paths;
const files = [
'global.css',
'global.less',
'global.stylus'
];
const globalCSSFile = files
.map(file => join(absSrcPath || '', file))
.filter(file => existsSync(file))
.slice(0, 1);
api.addEntryCodeAhead(
() => `${globalCSSFile
.map(file => `require('${winPath(relative(absTmpPath, file))}');`)
.join('')}`
);
};

View File