fix: add transform include for non-js files (#599)

* fix: add transform include for non-js files

* fix: optimize code
This commit is contained in:
ClarkXia 2022-10-26 15:46:42 +08:00
parent 99c8a96f50
commit ea2ebc29a0
1 changed files with 5 additions and 2 deletions

View File

@ -81,9 +81,12 @@ export default function importStylePlugin(options: TransformOptions) {
name: 'transform-import-style',
// Add plugin as a post plugin, so we do not need to deal with ts language.
enforce: 'post',
async transform(code: string, id: string, transformOption: { isServer: Boolean }) {
transformInclude(id: string) {
// Only transform source code.
if (transformOption.isServer || !code || !id.match(/\.(js|jsx|ts|tsx)$/) || id.match(/node_modules/)) {
return id.match(/\.(js|jsx|ts|tsx)$/) && !id.match(/node_modules/);
},
async transform(code: string, id: string, transformOption: { isServer: Boolean }) {
if (transformOption.isServer || !code) {
return null;
}
return await importStyle(code, options);