-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: applicable less and scss to vite (#1187)
- Loading branch information
atzcl
authored
Mar 30, 2021
1 parent
874f6a2
commit fb01176
Showing
6 changed files
with
70 additions
and
21 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
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,12 +1,58 @@ | ||
import { copy } from 'fs-extra' | ||
import { copy, readFile, writeFile, existsSync } from 'fs-extra' | ||
import glob from 'glob' | ||
|
||
glob(`./src/**/*.{less,scss}`, (err, files) => { | ||
if (err) { | ||
throw err | ||
export const runCopy = ({ | ||
esStr, | ||
libStr, | ||
}: Record<'esStr' | 'libStr', string>) => { | ||
const replaceOperation = async (filename: string) => { | ||
if (!existsSync(filename)) { | ||
return Promise.resolve() | ||
} | ||
|
||
const fileContent: string = (await readFile(filename)).toString() | ||
|
||
return writeFile( | ||
filename, | ||
fileContent.replace(new RegExp(libStr, 'g'), esStr) | ||
) | ||
} | ||
files.forEach((filename) => { | ||
copy(filename, filename.replace(/src\//, 'esm/')) | ||
copy(filename, filename.replace(/src\//, 'lib/')) | ||
|
||
return new Promise((resolve, reject) => { | ||
glob(`./src/**/*`, (err, files) => { | ||
if (err) { | ||
return reject(err) | ||
} | ||
|
||
const all = [] as Promise<unknown>[] | ||
|
||
for (let i = 0; i < files.length; i += 1) { | ||
const filename = files[i] | ||
|
||
if (/\.(less|scss)$/.test(filename)) { | ||
all.push(copy(filename, filename.replace(/src\//, 'esm/'))) | ||
all.push(copy(filename, filename.replace(/src\//, 'lib/'))) | ||
|
||
continue | ||
} | ||
|
||
if (/\/style.ts$/.test(filename)) { | ||
replaceOperation( | ||
filename.replace(/src\//, 'esm/').replace(/\.ts$/, '.js') | ||
) | ||
|
||
continue | ||
} | ||
} | ||
|
||
return Promise.all(all).then(resolve).catch(reject) | ||
}) | ||
}) | ||
} | ||
|
||
if (Boolean(process.env.INIT_RUN)) { | ||
runCopy({ | ||
esStr: 'antd/es/', | ||
libStr: 'antd/lib/', | ||
}) | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,6 @@ | ||
import { copy } from 'fs-extra' | ||
import glob from 'glob' | ||
import { runCopy } from '../antd/copy' | ||
|
||
glob(`./src/**/*.{less,scss}`, (err, files) => { | ||
if (err) { | ||
throw err | ||
} | ||
files.forEach((filename) => { | ||
copy(filename, filename.replace(/src\//, 'esm/')) | ||
copy(filename, filename.replace(/src\//, 'lib/')) | ||
}) | ||
runCopy({ | ||
esStr: '@alifd/next/es/', | ||
libStr: '@alifd/next/lib/', | ||
}) |
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