Skip to content

Commit

Permalink
perf: removed deprecated rollup API
Browse files Browse the repository at this point in the history
  • Loading branch information
Anidetrix committed Jan 14, 2022
1 parent bc19ac8 commit 46b73e6
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,10 @@ export default (options: Options = {}): Plugin => {
});

let extracted: Extracted[] = [];
let preserveModules: boolean;

const plugin: Plugin = {
name: "styles",

buildStart(opts) {
preserveModules = Boolean(opts.preserveModules);
},

async transform(code, id) {
if (!isIncluded(id) || !loaders.isSupported(id)) return null;

Expand Down Expand Up @@ -157,14 +152,14 @@ export default (options: Options = {}): Plugin => {
async generateBundle(opts, bundle) {
if (extracted.length === 0 || !(opts.dir || opts.file)) return;

// Respect rollup's 2.18.0 option changes
if (opts.preserveModules) preserveModules = opts.preserveModules;

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- either `file` or `dir` are always present
const dir = opts.dir ?? path.dirname(opts.file!);
const chunks = Object.values(bundle).filter((c): c is OutputChunk => c.type === "chunk");
const manual = chunks.filter(c => !c.facadeModuleId);
const emitted = preserveModules ? chunks : chunks.filter(c => c.isEntry || c.isDynamicEntry);
const emitted = opts.preserveModules
? chunks
: chunks.filter(c => c.isEntry || c.isDynamicEntry);

const emittedList: [string, string[]][] = [];

const getExtractedData = async (name: string, ids: string[]): Promise<ExtractedData> => {
Expand Down Expand Up @@ -206,7 +201,7 @@ export default (options: Options = {}): Plugin => {

const getName = (chunk: OutputChunk): string => {
if (opts.file) return path.parse(opts.file).name;
if (preserveModules) {
if (opts.preserveModules) {
const { dir, name } = path.parse(chunk.fileName);
return dir ? `${dir}/${name}` : name;
}
Expand Down

0 comments on commit 46b73e6

Please sign in to comment.