Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/pinia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"type": "module",
"main": "index.cjs",
"module": "dist/pinia.mjs",
"unpkg": "dist/pinia.iife.js",
"jsdelivr": "dist/pinia.iife.js",
"unpkg": "dist/pinia.esm-browser.js",
"jsdelivr": "dist/pinia.esm-browser.js",
"types": "dist/pinia.d.ts",
"exports": {
".": {
Expand Down
28 changes: 4 additions & 24 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ const outputConfigs = {
file: pkg.module.replace('mjs', 'cjs'),
format: `cjs`,
},
global: {
file: pkg.unpkg,
format: `iife`,
},
browser: {
file: 'dist/pinia.esm-browser.js',
format: `es`,
Expand All @@ -77,8 +73,6 @@ const packageConfigs = packageBuilds.map((format) =>
packageBuilds.forEach((buildName) => {
if (buildName === 'cjs') {
packageConfigs.push(createProductionConfig(buildName))
} else if (buildName === 'global') {
packageConfigs.push(createMinifiedConfig(buildName))
}
})

Expand All @@ -93,18 +87,12 @@ function createConfig(buildName, output, plugins = []) {
output.sourcemap = !!process.env.SOURCE_MAP
output.banner = banner
output.externalLiveBindings = false
output.globals = {
vue: 'Vue',
}

const isProductionBuild = /\.prod\.[cm]?js$/.test(output.file)
const isGlobalBuild = buildName === 'global'
const isRawESMBuild = buildName === 'browser'
const isNodeBuild = buildName === 'cjs'
const isBundlerESMBuild = buildName === 'browser' || buildName === 'mjs'

if (isGlobalBuild) output.name = pascalcase(pkg.name)

const shouldEmitDeclarations = !hasTSChecked

const tsPlugin = ts({
Expand All @@ -131,36 +119,28 @@ function createConfig(buildName, output, plugins = []) {

return {
input: `src/index.ts`,
// Global and Browser ESM builds inlines everything so that they can be
// Browser ESM build inlines everything so that it can be
// used alone.
external,
plugins: [
tsPlugin,
createReplacePlugin(
isProductionBuild,
isBundlerESMBuild,
// isBrowserBuild?
isRawESMBuild,
isGlobalBuild,
isNodeBuild
),
...nodePlugins,
...plugins,
],
output,
// onwarn: (msg, warn) => {
// if (!/Circular/.test(msg)) {
// warn(msg)
// }
// },
}
}

function createReplacePlugin(
isProduction,
isBundlerESMBuild,
isRawESMBuild,
isGlobalBuild,
isNodeBuild
) {
const __DEV__ =
Expand All @@ -186,11 +166,11 @@ function createReplacePlugin(
// this is only used during tests
__TEST__,
__FEATURE_PROD_DEVTOOLS__,
// If the build is expected to run directly in the browser (global / esm builds)
// If the build is expected to run directly in the browser (esm build)
__BROWSER__: JSON.stringify(isRawESMBuild),
// is targeting bundlers?
__BUNDLER__: JSON.stringify(isBundlerESMBuild),
__GLOBAL__: JSON.stringify(isGlobalBuild),
__GLOBAL__: 'false',
// is targeting Node (SSR)?
__NODE_JS__: JSON.stringify(isNodeBuild),
}
Expand Down Expand Up @@ -221,7 +201,7 @@ function createMinifiedConfig(format) {
return createConfig(
format,
{
file: `dist/${name}.${format === 'global' ? 'iife' : format}.prod.js`,
file: `dist/${name}.${format}.prod.js`,
format: outputConfigs[format].format,
},
[
Expand Down