Skip to content

Commit

Permalink
fix: rollup configuration
Browse files Browse the repository at this point in the history
This is a full refactoring of the rollup configuration to speed up builds, simplify the configuration prevent warnings and fix an error with the generated source maps.

In detail:
 - refactor: Combine the three non-esm outputs into a single configuration.

 - feat: Enabled source-maps for all build outputs.

 - fix: Use a separate TypeScript configuration (`tsconfig.build.json`) during build. This configuration only compiles the required typescript files and doesn't reproduce the directory structure in the dist-folder (see also the change in package.json). It also now generates source maps correctly (#834).

 - chore: Moved `fast-deep-equal` from dependencies to devDependencies. It is a very small function, and it has always been bundled in all of our outputs, so it's not actually required at runtime. This will be changed in the next major release.

 fixes #834
  • Loading branch information
usefulthink committed Feb 23, 2024
1 parent 959ea63 commit 793be37
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 63 deletions.
67 changes: 59 additions & 8 deletions package-lock.json

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

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"main": "dist/index.umd.js",
"unpkg": "dist/index.min.js",
"module": "dist/index.mjs",
"types": "dist/src/index.d.ts",
"types": "dist/index.d.ts",
"files": [
"dist/",
"src/"
Expand All @@ -33,9 +33,7 @@
"test": "jest src/*",
"test:e2e": "jest e2e/*"
},
"dependencies": {
"fast-deep-equal": "^3.1.3"
},
"dependencies": {},
"devDependencies": {
"@babel/preset-env": "^7.9.5",
"@babel/runtime-corejs3": "^7.9.2",
Expand All @@ -54,6 +52,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-jest": "^27.4.0",
"eslint-plugin-prettier": "^5.0.0",
"fast-deep-equal": "^3.1.3",
"geckodriver": "^4.2.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
Expand Down
86 changes: 35 additions & 51 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,71 +20,55 @@ import { nodeResolve } from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";

const babelOptions = {
extensions: [".js", ".ts"],
};

const terserOptions = { output: { comments: "" } };

const resolveOptions = {
mainFields: ["browser", "jsnext:main", "module", "main"],
const terserOptions = {
output: { comments: "some" },
};

export default [
// UMD and browser (iife) builds
{
input: "src/index.ts",
plugins: [
typescript({ tsconfig: "./tsconfig.json", declarationDir: "./" }),

nodeResolve(resolveOptions),
typescript({ tsconfig: "./tsconfig.build.json", declarationDir: "./" }),
nodeResolve({
mainFields: ["browser", "jsnext:main", "module", "main"],
}),
commonjs(),
babel(babelOptions),
terser(terserOptions),
babel({
extensions: [".js", ".ts"],
babelHelpers: "bundled",
}),
],
output: {
file: "dist/index.umd.js",
format: "umd",
name: "google.maps.plugins.loader",
sourcemap: true,
},
},
{
input: "src/index.ts",
plugins: [
typescript({ tsconfig: "./tsconfig.json", declarationDir: "./" }),

nodeResolve(resolveOptions),
commonjs(),
babel(babelOptions),
terser(terserOptions),
output: [
{
file: "dist/index.umd.js",
format: "umd",
name: "google.maps.plugins.loader",
sourcemap: true,
plugins: [terser(terserOptions)],
},
{
file: "dist/index.min.js",
format: "iife",
name: "google.maps.plugins.loader",
sourcemap: true,
plugins: [terser(terserOptions)],
},
{
file: "dist/index.dev.js",
format: "iife",
name: "google.maps.plugins.loader",
sourcemap: true,
},
],
output: {
file: "dist/index.min.js",
format: "iife",
name: "google.maps.plugins.loader",
},
},
{
input: "src/index.ts",
plugins: [
typescript({ tsconfig: "./tsconfig.json", declarationDir: "./" }),

nodeResolve(resolveOptions),
commonjs(),
babel(babelOptions),
],
output: {
file: "dist/index.dev.js",
format: "iife",
name: "google.maps.plugins.loader",
},
},
// ESM build
{
input: "src/index.ts",
plugins: [
typescript({ tsconfig: "./tsconfig.json", declarationDir: "./" }),

nodeResolve(resolveOptions),
typescript({ tsconfig: "./tsconfig.build.json", declarationDir: "./" }),
nodeResolve(),
commonjs(),
],
output: {
Expand Down
6 changes: 6 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": { "noEmit": false },
"include": ["src/**/*"],
"exclude": ["node_modules", "./dist", "./e2e", "src/**/*.test.ts"]
}

0 comments on commit 793be37

Please sign in to comment.