-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add back rollup for charts build * clean before build * changelog
- Loading branch information
Showing
5 changed files
with
225 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: changed | ||
|
||
Changed back to build with Rollup |
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 |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Import necessary plugins for building the library | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import json from '@rollup/plugin-json'; | ||
import resolve from '@rollup/plugin-node-resolve'; | ||
import terser from '@rollup/plugin-terser'; | ||
import typescript from '@rollup/plugin-typescript'; | ||
import { defineConfig } from 'rollup'; | ||
import dts from 'rollup-plugin-dts'; | ||
import peerDepsExternal from 'rollup-plugin-peer-deps-external'; | ||
import postcss from 'rollup-plugin-postcss'; | ||
|
||
// Common plugins used across all build configurations | ||
const commonPlugins = [ | ||
// Automatically externalize peer dependencies | ||
peerDepsExternal( { | ||
includeDependencies: true, | ||
} ), | ||
// Locate and bundle third-party dependencies from node_modules | ||
resolve( { | ||
preferBuiltins: true, | ||
extensions: [ '.tsx', '.ts', '.js', '.jsx' ], | ||
} ), | ||
// Convert CommonJS modules to ES6 | ||
commonjs(), | ||
// Allow importing JSON files | ||
json(), | ||
// Process SCSS/CSS modules | ||
postcss( { | ||
// Configure CSS modules with scoped names | ||
modules: { | ||
generateScopedName: '[name]__[local]__[hash:base64:5]', | ||
}, | ||
extract: 'style.css', | ||
autoModules: false, | ||
use: [ 'sass' ], | ||
} ), | ||
]; | ||
|
||
// Main bundle configuration for the entire library | ||
const mainConfig = { | ||
// Entry point for the bundle | ||
input: 'src/index.ts', | ||
// Output configuration for different module formats | ||
output: [ | ||
{ | ||
file: './dist/cjs/index.js', | ||
format: 'cjs', // CommonJS format for Node.js | ||
sourcemap: true, | ||
sourcemapPathTransform: relativeSourcePath => { | ||
return `/@automattic/charts/${ relativeSourcePath }`; | ||
}, | ||
}, | ||
{ | ||
file: './dist/mjs/index.js', | ||
format: 'esm', // ES modules for modern bundlers | ||
sourcemap: true, | ||
}, | ||
], | ||
// Mark all dependencies as external to avoid bundling them | ||
external: [ 'react', 'react-dom', /^@visx\/.*/, '@react-spring/web', 'clsx', 'tslib' ], | ||
plugins: [ | ||
...commonPlugins, | ||
// TypeScript compilation | ||
typescript( { | ||
tsconfig: './tsconfig.json', | ||
declaration: false, // Declarations handled by dts plugin | ||
sourceMap: true, | ||
compilerOptions: { | ||
verbatimModuleSyntax: true, | ||
}, | ||
} ), | ||
terser(), | ||
], | ||
// Handle circular dependencies warning | ||
onwarn( warning, warn ) { | ||
if ( warning.code === 'CIRCULAR_DEPENDENCY' ) { | ||
return; | ||
} | ||
warn( warning ); | ||
}, | ||
}; | ||
|
||
// List of components to build individually | ||
const components = [ | ||
'components/bar-chart', | ||
'components/line-chart', | ||
'components/pie-chart', | ||
'components/pie-semi-circle-chart', | ||
'components/tooltip', | ||
'components/legend', | ||
'components/grid-control', | ||
'providers/theme', | ||
]; | ||
|
||
// Generate individual bundles for each component | ||
const componentConfigs = components.map( component => ( { | ||
// Component entry point - try both .tsx and .ts extensions | ||
input: `src/${ component }/index`, | ||
// Output both ESM and CJS formats | ||
output: [ | ||
{ | ||
file: `dist/mjs/${ component }/index.js`, | ||
format: 'esm', | ||
sourcemap: true, | ||
}, | ||
{ | ||
file: `dist/cjs/${ component }/index.js`, | ||
format: 'cjs', | ||
sourcemap: true, | ||
}, | ||
], | ||
// Same external config as main bundle | ||
external: [ 'react', 'react-dom', /^@visx\/.*/, '@react-spring/web', 'clsx', 'tslib' ], | ||
plugins: [ | ||
...commonPlugins, | ||
typescript( { | ||
tsconfig: './tsconfig.json', | ||
declaration: false, | ||
sourceMap: true, | ||
compilerOptions: { | ||
verbatimModuleSyntax: true, | ||
}, | ||
} ), | ||
terser(), | ||
], | ||
} ) ); | ||
|
||
// Configuration for generating TypeScript declaration files | ||
const typesConfig = { | ||
input: 'src/index.ts', | ||
output: [ { file: 'dist/index.d.ts', format: 'es' } ], | ||
plugins: [ | ||
dts( { | ||
respectExternal: true, | ||
} ), | ||
], | ||
// Don't include style imports in type definitions | ||
external: [ /\.scss$/, /\.css$/, 'react', /@types\/.*/, /^@visx\/.*/, 'react/jsx-runtime' ], | ||
}; | ||
|
||
// Export all configurations to be built in parallel | ||
export default defineConfig( [ mainConfig, ...componentConfigs, typesConfig ] ); |
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,10 +1,9 @@ | ||
{ | ||
"extends": "jetpack-js-tools/tsconfig.tsc-declaration-only.json", | ||
"extends": "jetpack-js-tools/tsconfig.base.json", | ||
"compilerOptions": { | ||
"typeRoots": [ "./node_modules/@types/", "src/*" ], | ||
"outDir": "./dist/types" | ||
"typeRoots": [ "./node_modules/@types/", "src/*" ] | ||
}, | ||
// List all sources and source-containing subdirs. | ||
"include": [ "./src/index.ts" ], | ||
"include": [ "./src" ], | ||
"exclude": [ "node_modules", "dist", "**/stories/**" ] | ||
} |