Skip to content

Commit 947b1d0

Browse files
committed
fix(build): add production build for every build type
1 parent 4f622a0 commit 947b1d0

File tree

1 file changed

+13
-30
lines changed

1 file changed

+13
-30
lines changed

rollup.config.mjs

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-check
2-
import { dirname, resolve } from 'node:path'
2+
import { dirname, parse, resolve } from 'node:path'
33
import { fileURLToPath } from 'node:url'
44
import { readFileSync } from 'node:fs'
55
import ts from 'rollup-plugin-typescript2'
@@ -23,7 +23,6 @@ const packageDir = resolve(packagesDir, process.env.TARGET)
2323
const pkg = JSON.parse(
2424
readFileSync(resolve(packageDir, `package.json`), 'utf-8')
2525
)
26-
const name = pkg.name
2726

2827
function getAuthors(pkg) {
2928
const { contributors, author } = pkg
@@ -68,18 +67,10 @@ const outputConfigs = {
6867
},
6968
}
7069

71-
const packageBuilds = Object.keys(outputConfigs)
72-
const packageConfigs = packageBuilds.map((format) =>
73-
createConfig(format, outputConfigs[format])
74-
)
75-
76-
// only add the production ready if we are bundling the options
77-
packageBuilds.forEach((buildName) => {
78-
if (buildName === 'cjs') {
79-
packageConfigs.push(createProductionConfig(buildName))
80-
} else if (buildName === 'global' || buildName === 'browser') {
81-
packageConfigs.push(createMinifiedConfig(buildName))
82-
}
70+
const packageConfigs = []
71+
Object.entries(outputConfigs).forEach(([buildName, output]) => {
72+
packageConfigs.push(createConfig(buildName, output))
73+
packageConfigs.push(createProductionConfig(buildName, output))
8374
})
8475

8576
export default packageConfigs
@@ -99,7 +90,7 @@ function createConfig(buildName, output, plugins = []) {
9990

10091
const isProductionBuild = /\.prod\.[cm]?js$/.test(output.file)
10192
const isGlobalBuild = buildName === 'global'
102-
const isRawESMBuild = buildName.includes('browser')
93+
const isRawESMBuild = buildName === 'browser'
10394
const isNodeBuild = buildName === 'cjs'
10495
const isBundlerESMBuild = buildName === 'browser' || buildName === 'mjs'
10596

@@ -126,7 +117,7 @@ function createConfig(buildName, output, plugins = []) {
126117
hasTSChecked = true
127118

128119
const external = ['vue']
129-
if (buildName !== 'browser-prod') external.push('@vue/devtools-api')
120+
if (!isProductionBuild) external.push('@vue/devtools-api')
130121

131122
const nodePlugins = [nodeResolve(), commonjs()]
132123

@@ -209,25 +200,17 @@ function createReplacePlugin(
209200
})
210201
}
211202

212-
function createProductionConfig(format) {
213-
const extension = format === 'cjs' ? 'cjs' : 'js'
214-
const descriptor = format === 'cjs' ? '' : `.${format}`
215-
return createConfig(format, {
216-
file: `dist/${name}${descriptor}.prod.${extension}`,
217-
format: outputConfigs[format].format,
218-
})
219-
}
220-
221-
function createMinifiedConfig(format) {
203+
function createProductionConfig(buildName, output) {
204+
const parsedPath = parse(output.file)
222205
return createConfig(
223-
format === 'browser' ? 'browser-prod' : format,
206+
buildName,
224207
{
225-
file: `dist/${name}.${format === 'browser' ? 'esm-browser' : format === 'global' ? 'iife' : format}.prod.js`,
226-
format: outputConfigs[format].format,
208+
file: resolve(parsedPath.dir, `${parsedPath.name}.prod${parsedPath.ext}`),
209+
format: output.format,
227210
},
228211
[
229212
terser({
230-
module: /^esm/.test(format),
213+
module: output.format === 'es',
231214
compress: {
232215
ecma: 2015,
233216
pure_getters: true,

0 commit comments

Comments
 (0)