-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dist-module): apply plugins to dist-module imports
- Loading branch information
1 parent
db0dadb
commit 1392b0c
Showing
8 changed files
with
138 additions
and
32 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
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,24 +1,44 @@ | ||
import * as d from '../../declarations'; | ||
import { createCompiler } from '../browser/create-compiler'; | ||
import { Plugin } from 'rollup'; | ||
import { runPluginTransformsEsmImports } from '../plugin/plugin'; | ||
|
||
|
||
export const cssTransformer = (buildCtx: d.BuildCtx): Plugin => { | ||
export const cssTransformer = (config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx): Plugin => { | ||
const compiler = createCompiler(); | ||
|
||
return { | ||
name: 'cssTransformer', | ||
|
||
resolveId(importee: string, importer: string) { | ||
return compiler.resolveId(importee, importer); | ||
const r = compiler.resolveId(importee, importer); | ||
if (r != null && r.type === 'css') { | ||
if (KNOWN_PREPROCESSOR_EXTS.has(r.importerExt) && r.importerExt !== r.resolvedFileExt) { | ||
// basically for sass paths without an extension | ||
r.resolvedFileExt = r.importerExt; | ||
r.resolvedFileName += '.' + r.resolvedFileExt; | ||
r.resolvedFilePath += '.' + r.resolvedFileExt; | ||
r.resolvedId = `${r.resolvedFilePath}?${r.params}`; | ||
compiler.setResolvedData(r.resolvedId, r); | ||
} | ||
return r.resolvedId; | ||
} | ||
return null; | ||
}, | ||
|
||
async transform(code: string, id: string) { | ||
const results = await compiler.transform(code, id); | ||
if (results != null) { | ||
buildCtx.diagnostics.push(...results.diagnostics); | ||
return results; | ||
const r = compiler.getResolvedData(id); | ||
if (r != null) { | ||
const pluginTransforms = await runPluginTransformsEsmImports(config, compilerCtx, buildCtx, code, id); | ||
const results = await compiler.transform(pluginTransforms.code, id); | ||
if (results != null) { | ||
buildCtx.diagnostics.push(...results.diagnostics); | ||
return results; | ||
} | ||
} | ||
return null; | ||
} | ||
}; | ||
}; | ||
|
||
const KNOWN_PREPROCESSOR_EXTS = new Set(['sass', 'scss', 'styl', 'less', 'pcss']); |
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
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