Skip to content

Commit d3a919b

Browse files
committed
chore: update style
1 parent 261e7d0 commit d3a919b

File tree

5 files changed

+41
-123
lines changed

5 files changed

+41
-123
lines changed

antd-tools/getBabelCommonConfig.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ module.exports = function (modules) {
2020
resolve('@babel/plugin-transform-runtime'),
2121
{
2222
useESModules: modules === false,
23-
version: '^7.10.4',
23+
version:
24+
require(`${process.cwd()}/package.json`).dependencies['@babel/runtime'] || '^7.10.4',
2425
},
2526
],
2627
// resolve('babel-plugin-inline-import-data-uri'),
@@ -39,7 +40,7 @@ module.exports = function (modules) {
3940
{
4041
modules,
4142
targets: {
42-
browsers: ['last 2 versions', 'Firefox ESR', '> 1%', 'not ie 11'],
43+
browsers: ['last 2 versions', 'Firefox ESR', '> 1%', 'ie >= 11'],
4344
},
4445
},
4546
],

antd-tools/getWebpackConfig.js

-30
Original file line numberDiff line numberDiff line change
@@ -150,36 +150,6 @@ function getWebpackConfig(modules, esm = false) {
150150
},
151151
],
152152
},
153-
{
154-
test: /\.less$/,
155-
use: [
156-
MiniCssExtractPlugin.loader,
157-
{
158-
loader: 'css-loader',
159-
options: {
160-
sourceMap: true,
161-
},
162-
},
163-
{
164-
loader: 'postcss-loader',
165-
options: {
166-
postcssOptions: {
167-
plugins: ['autoprefixer'],
168-
},
169-
sourceMap: true,
170-
},
171-
},
172-
{
173-
loader: 'less-loader',
174-
options: {
175-
lessOptions: {
176-
javascriptEnabled: true,
177-
},
178-
sourceMap: true,
179-
},
180-
},
181-
],
182-
},
183153
// Images
184154
{
185155
test: svgRegex,

antd-tools/gulpfile.js

+38-53
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const getBabelCommonConfig = require('./getBabelCommonConfig');
55
const merge2 = require('merge2');
66
const { execSync } = require('child_process');
77
const through2 = require('through2');
8-
const transformLess = require('./transformLess');
98
const webpack = require('webpack');
109
const babel = require('gulp-babel');
1110
const argv = require('minimist')(process.argv.slice(2));
@@ -27,15 +26,22 @@ const compareVersions = require('compare-versions');
2726
const getTSCommonConfig = require('./getTSCommonConfig');
2827
const replaceLib = require('./replaceLib');
2928
const sortApiTable = require('./sortApiTable');
29+
const { glob } = require('glob');
3030

3131
const packageJson = require(getProjectPath('package.json'));
3232
const tsDefaultReporter = ts.reporter.defaultReporter();
3333
const cwd = process.cwd();
3434
const libDir = getProjectPath('lib');
3535
const esDir = getProjectPath('es');
36+
const localeDir = getProjectPath('locale');
3637

3738
const tsConfig = getTSCommonConfig();
3839

40+
// FIXME: hard code, not find typescript can modify the path resolution
41+
const localeDts = `import type { Locale } from '../lib/locale-provider';
42+
declare const localeValues: Locale;
43+
export default localeValues;`;
44+
3945
function dist(done) {
4046
rimraf.sync(path.join(cwd, 'dist'));
4147
process.env.RUN_ENV = 'PRODUCTION';
@@ -108,6 +114,11 @@ gulp.task('tsc', () =>
108114
),
109115
);
110116

117+
gulp.task('clean', () => {
118+
rimraf.sync(getProjectPath('_site'));
119+
rimraf.sync(getProjectPath('_data'));
120+
});
121+
111122
function babelify(js, modules) {
112123
const babelConfig = getBabelCommonConfig(modules);
113124
babelConfig.babelrc = false;
@@ -118,17 +129,7 @@ function babelify(js, modules) {
118129
const stream = js.pipe(babel(babelConfig)).pipe(
119130
through2.obj(function z(file, encoding, next) {
120131
this.push(file.clone());
121-
if (file.path.match(/\/style\/index\.(js|jsx|ts|tsx)$/)) {
122-
const content = file.contents.toString(encoding);
123-
file.contents = Buffer.from(
124-
content
125-
.replace(/\/style\/?'/g, "/style/css'")
126-
.replace(/\/style\/?"/g, '/style/css"')
127-
.replace(/\.less/g, '.css'),
128-
);
129-
file.path = file.path.replace(/index\.(js|jsx|ts|tsx)$/, 'css.js');
130-
this.push(file);
131-
} else if (modules !== false) {
132+
if (modules !== false) {
132133
const content = file.contents.toString(encoding);
133134
file.contents = Buffer.from(
134135
content
@@ -144,47 +145,9 @@ function babelify(js, modules) {
144145
}
145146

146147
function compile(modules) {
147-
const { compile: { transformTSFile, transformFile, includeLessFile = [] } = {} } = getConfig();
148+
const { compile: { transformTSFile, transformFile } = {} } = getConfig();
148149
rimraf.sync(modules !== false ? libDir : esDir);
149150

150-
// =============================== LESS ===============================
151-
const less = gulp
152-
.src(['components/**/*.less'])
153-
.pipe(
154-
through2.obj(function (file, encoding, next) {
155-
// Replace content
156-
const cloneFile = file.clone();
157-
const content = file.contents.toString().replace(/^\uFEFF/, '');
158-
159-
cloneFile.contents = Buffer.from(content);
160-
161-
// Clone for css here since `this.push` will modify file.path
162-
const cloneCssFile = cloneFile.clone();
163-
164-
this.push(cloneFile);
165-
166-
// Transform less file
167-
if (
168-
file.path.match(/(\/|\\)style(\/|\\)index\.less$/) ||
169-
file.path.match(/(\/|\\)style(\/|\\)v2-compatible-reset\.less$/) ||
170-
includeLessFile.some(regex => file.path.match(regex))
171-
) {
172-
transformLess(cloneCssFile.contents.toString(), cloneCssFile.path)
173-
.then(css => {
174-
cloneCssFile.contents = Buffer.from(css);
175-
cloneCssFile.path = cloneCssFile.path.replace(/\.less$/, '.css');
176-
this.push(cloneCssFile);
177-
next();
178-
})
179-
.catch(e => {
180-
console.error(e);
181-
});
182-
} else {
183-
next();
184-
}
185-
}),
186-
)
187-
.pipe(gulp.dest(modules === false ? esDir : libDir));
188151
const assets = gulp
189152
.src(['components/**/*.@(png|svg)'])
190153
.pipe(gulp.dest(modules === false ? esDir : libDir));
@@ -259,7 +222,26 @@ function compile(modules) {
259222
tsResult.on('end', check);
260223
const tsFilesStream = babelify(tsResult.js, modules);
261224
const tsd = tsResult.dts.pipe(gulp.dest(modules === false ? esDir : libDir));
262-
return merge2([less, tsFilesStream, tsd, assets, transformFileStream].filter(s => s));
225+
return merge2([tsFilesStream, tsd, assets, transformFileStream].filter(s => s));
226+
}
227+
228+
function generateLocale() {
229+
if (!fs.existsSync(localeDir)) {
230+
fs.mkdirSync(localeDir);
231+
}
232+
233+
const localeFiles = glob.sync('components/locale/*.ts?(x)');
234+
localeFiles.forEach(item => {
235+
const match = item.match(/components\/locale\/(.*)\.tsx?/);
236+
if (match) {
237+
const locale = match[1];
238+
fs.writeFileSync(
239+
path.join(localeDir, `${locale}.js`),
240+
`module.exports = require('../lib/locale/${locale}');`,
241+
);
242+
fs.writeFileSync(path.join(localeDir, `${locale}.d.ts`), localeDts);
243+
}
244+
});
263245
}
264246

265247
function tag() {
@@ -395,7 +377,10 @@ gulp.task('compile-with-es', done => {
395377

396378
gulp.task('compile-with-lib', done => {
397379
console.log('[Parallel] Compile to js...');
398-
compile().on('finish', done);
380+
compile().on('finish', () => {
381+
generateLocale();
382+
done();
383+
});
399384
});
400385

401386
gulp.task('compile-finalize', done => {

antd-tools/transformLess.js

-27
This file was deleted.

antd-tools/utils/styleUtil.js

-11
This file was deleted.

0 commit comments

Comments
 (0)