Skip to content

Commit

Permalink
chore: Use rollup-plugin-node-externals
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlancollins committed Jun 3, 2023
1 parent e3e1e82 commit 9262d9f
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 48 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"react-dom": "^18.2.0",
"rimraf": "^5.0.1",
"rollup": "^3.23.0",
"rollup-plugin-node-externals": "^6.1.0",
"rollup-plugin-preserve-directives": "^0.2.0",
"rollup-plugin-visualizer": "^5.9.0",
"rollup-preset-solid": "^2.0.1",
Expand Down
3 changes: 0 additions & 3 deletions packages/query-async-storage-persister/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ export default defineConfig(
jsName: 'QueryAsyncStoragePersister',
outputFile: 'index',
entryFile: './src/index.ts',
globals: {
'@tanstack/query-persist-client-core': 'QueryPersistClientCore',
},
}),
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ export default defineConfig(
jsName: 'QueryBroadcastClient',
outputFile: 'index',
entryFile: './src/index.ts',
globals: {
'@tanstack/query-core': 'QueryCore',
'broadcast-channel': 'BroadcastChannel',
},
}),
)
1 change: 0 additions & 1 deletion packages/query-core/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ export default defineConfig(
jsName: 'QueryCore',
outputFile: 'index',
entryFile: './src/index.ts',
globals: {},
}),
)
3 changes: 0 additions & 3 deletions packages/query-persist-client-core/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ export default defineConfig(
jsName: 'QueryPersistClientCore',
outputFile: 'index',
entryFile: './src/index.ts',
globals: {
'@tanstack/query-core': 'QueryCore',
},
}),
)
3 changes: 0 additions & 3 deletions packages/query-sync-storage-persister/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ export default defineConfig(
jsName: 'QuerySyncStoragePersister',
outputFile: 'index',
entryFile: './src/index.ts',
globals: {
'@tanstack/query-persist-client-core': 'QueryPersistClientCore',
},
}),
)
13 changes: 0 additions & 13 deletions packages/react-query-devtools/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,12 @@ export default defineConfig([
jsName: 'ReactQueryDevtools',
outputFile: 'index',
entryFile: './src/index.ts',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'@tanstack/react-query': 'ReactQuery',
'@tanstack/query-devtools': 'TanstackQueryDevtools',
},
}),
buildConfigs({
name: 'react-query-devtools-prod',
jsName: 'ReactQueryDevtools',
outputFile: 'index.prod',
entryFile: './src/index.ts',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'@tanstack/react-query': 'ReactQuery',
'@tanstack/match-sorter-utils': 'MatchSorterUtils',
superjson: 'SuperJson',
},
forceDevEnv: true,
forceBundle: true,
}),
Expand Down
5 changes: 0 additions & 5 deletions packages/react-query-persist-client/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@ export default defineConfig(
jsName: 'ReactQueryPersistClient',
outputFile: 'index',
entryFile: './src/index.ts',
globals: {
react: 'React',
'@tanstack/query-persist-client-core': 'QueryPersistClientCore',
'@tanstack/react-query': 'ReactQuery',
},
}),
)
6 changes: 0 additions & 6 deletions packages/react-query/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,5 @@ export default defineConfig(
jsName: 'ReactQuery',
outputFile: 'index',
entryFile: './src/index.ts',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'@tanstack/query-core': 'QueryCore',
'react-native': 'ReactNative',
},
}),
)
7 changes: 0 additions & 7 deletions packages/vue-query/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,5 @@ export default defineConfig(
jsName: 'VueQuery',
outputFile: 'index',
entryFile: './src/index.ts',
globals: {
'@tanstack/query-core': 'QueryCore',
vue: 'Vue',
'vue-demi': 'Vue',
'@tanstack/match-sorter-utils': 'MatchSorter',
'@vue/devtools-api': 'DevtoolsApi',
},
}),
)
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

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

10 changes: 7 additions & 3 deletions scripts/getRollupConfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { visualizer } from 'rollup-plugin-visualizer'
import replace from '@rollup/plugin-replace'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonJS from '@rollup/plugin-commonjs'
import externals from 'rollup-plugin-node-externals'
import withSolid from 'rollup-preset-solid'
import preserveDirectives from 'rollup-plugin-preserve-directives'
import { rootDir } from './config.mjs'
Expand Down Expand Up @@ -33,14 +34,12 @@ const babelPlugin = () =>
* @param {string} opts.jsName - The JavaScript name.
* @param {string} opts.outputFile - The output file.
* @param {string} opts.entryFile - The entry file.
* @param {Record<string, string>} opts.globals - The globals record.
* @param {boolean} [opts.forceDevEnv] - Flag indicating whether to force development environment.
* @param {boolean} [opts.forceBundle] - Flag indicating whether to force bundling.
* @returns {import('rollup').RollupOptions}
*/
export function buildConfigs(opts) {
const input = [opts.entryFile]
const externalDeps = Object.keys(opts.globals)
const forceDevEnv = opts.forceDevEnv || false
const forceBundle = opts.forceBundle || false

Expand Down Expand Up @@ -81,12 +80,17 @@ export function buildConfigs(opts) {
return {
input,
output: forceBundle ? bundleOutput : normalOutput,
external: (moduleName) => externalDeps.includes(moduleName),
plugins: [
commonJS(),
babelPlugin(),
nodeResolve({ extensions: ['.ts', '.tsx', '.native.ts'] }),
forceDevEnv ? forceEnvPlugin('development') : undefined,
externals({
packagePath: './package.json',
deps: true,
devDeps: true,
peerDeps: true,
}),
preserveDirectives(),
visualizer({
filename: `./build/stats-html.html`,
Expand Down

0 comments on commit 9262d9f

Please sign in to comment.