Skip to content

Commit

Permalink
feat: code splitting rework /w preserveModules support
Browse files Browse the repository at this point in the history
  • Loading branch information
Anidetrix committed May 16, 2020
1 parent eba681b commit 8f44a7a
Show file tree
Hide file tree
Showing 14 changed files with 498 additions and 250 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
"prefer-template": "error",
"sort-vars": "error",
"unicorn/no-fn-reference-in-iterator": "off",
"unicorn/no-null": "off",
"unicorn/no-reduce": "off",
"unicorn/prefer-set-has": "off",
"unicorn/prevent-abbreviations": "off",
Expand Down
473 changes: 358 additions & 115 deletions __tests__/__snapshots__/index.test.ts.snap

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions __tests__/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable jest/no-export */
import path from "path";
import fs from "fs-extra";
import { Plugin, rollup, OutputOptions } from "rollup";
import { Plugin, rollup, InputOptions, OutputOptions } from "rollup";

import styles from "../../src";
import { Options } from "../../src/types";
Expand All @@ -13,6 +13,7 @@ export type WriteData = {
outDir?: string;
options?: Options;
plugins?: Plugin[];
inputOpts?: InputOptions;
outputOpts?: OutputOptions;
};

Expand Down Expand Up @@ -40,12 +41,11 @@ export const fixture = (...args: string[]): string =>
export async function write(data: WriteData): Promise<WriteResult> {
const outDir = fixture("dist", data.outDir ?? data.title ?? "");
const input = Array.isArray(data.input) ? data.input.map(i => fixture(i)) : fixture(data.input);
const multiEntry = Array.isArray(data.input) ? data.input.length > 1 : false;

const bundle = await rollup({
...data.inputOpts,
input,
plugins: data.plugins ?? [styles(data.options)],
preserveModules: multiEntry,
onwarn: (warning, warn) => {
if (warning.code === "EMPTY_BUNDLE") return;
if (warning.source === "lit-element") return;
Expand Down
20 changes: 20 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,26 @@ validateMany("code-splitting", [
sourceMap: true,
},
},
{
title: "preserve-modules",
input: "code-splitting/index.js",
options: {
mode: "extract",
modules: true,
sourceMap: true,
},
inputOpts: { preserveModules: true },
},
{
title: "preserve-modules-single",
input: "code-splitting/index.js",
options: {
mode: "extract",
modules: true,
sourceMap: true,
},
inputOpts: { preserveModules: true },
},
{
title: "multi-entry",
input: ["code-splitting/index.js", "code-splitting/index2.js"],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"eslint-config-prettier": "^6.11.0",
"eslint-import-resolver-node": "^0.3.3",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.11.0",
"eslint-plugin-jest": "^23.13.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-unicorn": "^20.0.0",
"fibers": "^5.0.0",
Expand All @@ -109,7 +109,7 @@
"postcss-custom-properties": "^9.1.1",
"prettier": "^2.0.5",
"rollup": "^2.10.2",
"rollup-plugin-dts": "^1.4.3",
"rollup-plugin-dts": "^1.4.4",
"rollup-plugin-lit-css": "^2.0.3",
"rollup-plugin-node-externals": "^2.1.6",
"rollup-plugin-terser": "^5.3.0",
Expand Down
68 changes: 37 additions & 31 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = {
"prefer-template": "error",
"sort-vars": "error",
"unicorn/no-fn-reference-in-iterator": "off",
"unicorn/no-null": "off",
"unicorn/no-reduce": "off",
"unicorn/prefer-set-has": "off",
"unicorn/prevent-abbreviations": "off",
Expand Down
Loading

0 comments on commit 8f44a7a

Please sign in to comment.