Skip to content

Commit

Permalink
make a cdn build for vue-router
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Skinner committed Sep 15, 2023
1 parent d05609a commit 8df0a04
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/vue-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"access": "public"
},
"scripts": {
"build": "npm run build:npm",
"build": "npm run build:npm && npm run build:cdn",
"build:npm": "rollup --config rollup.config.npm.mjs",
"build:cdn": "rollup --config rollup.config.cdn.mjs",
"clean": "rm -rf dist/*"
},
"bugs": {
Expand Down
53 changes: 53 additions & 0 deletions packages/vue-router/rollup.config.cdn.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import fs from 'fs'
import terser from '@rollup/plugin-terser'
import replace from '@rollup/plugin-replace'
import commonjs from '@rollup/plugin-commonjs'
import typescript from '@rollup/plugin-typescript'
import nodeResolve from '@rollup/plugin-node-resolve'

// the built files for the CDN go in the top-level 'build' directory so they
// can't accidentally be uploaded to NPM somehow
const buildDirectory = '../../build'

if (!fs.existsSync(buildDirectory)) {
fs.mkdirSync(buildDirectory)
}

const packageJson = JSON.parse(fs.readFileSync('./package.json'))

const sharedOutputOptions = {
format: 'es',
name: 'BugsnagVueRouterPerformance',
generatedCode: {
preset: 'es2015',
},
sourcemap: true,
}

export default {
input: 'lib/index.ts',
output: [
{
...sharedOutputOptions,
file: `${buildDirectory}/bugsnag-vue-router-performance.js`,
},
{
...sharedOutputOptions,
file: `${buildDirectory}/bugsnag-vue-router-performance.min.js`,
compact: true,
plugins: [terser({ ecma: 2015 })],
},
],
plugins: [
replace({
preventAssignment: true,
values: { __VERSION__: packageJson.version },
}),
typescript({
// don't output anything if there's a TS error
noEmitOnError: true,
}),
commonjs(),
nodeResolve({ browser: true }),
],
}
3 changes: 2 additions & 1 deletion test/browser/features/fixtures/packages/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const cdnOutputOptions = {
: 'import BugsnagPerformance from "/bugsnag-performance.min.js"\n',
globals: {
'@bugsnag/browser-performance': 'BugsnagPerformance',
'@bugsnag/vue-router-performance': 'BugsnagVueRouterPerformance',
},
}

Expand All @@ -28,7 +29,7 @@ export default {
nodeResolve({ browser: true, jail: path.resolve(`${__dirname}/..`) }),
commonjs()
],
...(isCdnBuild ? { external: ['@bugsnag/browser-performance'] } : {}),
...(isCdnBuild ? { external: ['@bugsnag/browser-performance', '@bugsnag/vue-router-performance'] } : {}),
onLog (level, log, defaultHandler) {
// turn warnings into errors
if (level === 'warn') {
Expand Down

0 comments on commit 8df0a04

Please sign in to comment.