mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-24 13:50:34 +03:00
fix: rollup config, esm-bundler builds are also browser builds
This commit is contained in:
+44
-30
@@ -9,9 +9,10 @@ import ts from 'rollup-plugin-typescript2'
|
|||||||
import dts from 'rollup-plugin-dts'
|
import dts from 'rollup-plugin-dts'
|
||||||
import defaultsDeep from 'lodash/defaultsDeep'
|
import defaultsDeep from 'lodash/defaultsDeep'
|
||||||
|
|
||||||
|
const r = p => path.resolve(__dirname, p)
|
||||||
const pkg = require('../package.json')
|
const pkg = require('../package.json')
|
||||||
|
|
||||||
const banner = `/**
|
const banner = `/**
|
||||||
* ${pkg.name} v${pkg.version}
|
* ${pkg.name} v${pkg.version}
|
||||||
* (c) ${new Date().getFullYear()}
|
* (c) ${new Date().getFullYear()}
|
||||||
* - Pim (@pimlie)
|
* - Pim (@pimlie)
|
||||||
@@ -22,14 +23,15 @@ const banner = `/**
|
|||||||
|
|
||||||
let didTS = false
|
let didTS = false
|
||||||
|
|
||||||
function rollupConfig({
|
function rollupConfig ({
|
||||||
plugins = [],
|
plugins = [],
|
||||||
external = [],
|
external = [],
|
||||||
...config
|
...config
|
||||||
}) {
|
}) {
|
||||||
|
const { file, format } = config?.output
|
||||||
const isBrowserBuild = !config.output || !config.output.format || config.output.format === 'iife' || config.output.file.includes('-browser.')
|
const isProductionBuild = file.includes('.prod.')
|
||||||
const isProductionBuild = config.output.file.includes('.prod.')
|
const isESMBundlerBuild = file.includes('.esm-bundler.')
|
||||||
|
const isBrowserBuild = format === 'iife' || file.includes('-browser.')
|
||||||
|
|
||||||
const replaceConfig = {
|
const replaceConfig = {
|
||||||
preventAssignment: true,
|
preventAssignment: true,
|
||||||
@@ -37,8 +39,8 @@ function rollupConfig({
|
|||||||
delimiters: ['', ''],
|
delimiters: ['', ''],
|
||||||
values: {
|
values: {
|
||||||
'process.env.NODE_ENV': JSON.stringify(isProductionBuild ? 'production' : 'development'),
|
'process.env.NODE_ENV': JSON.stringify(isProductionBuild ? 'production' : 'development'),
|
||||||
'__DEV__': config.output.format === 'es' && !isBrowserBuild ? "(process.env.NODE_ENV !== 'production')" : !isProductionBuild,
|
__DEV__: config.output.format === 'es' && !isBrowserBuild ? "(process.env.NODE_ENV !== 'production')" : !isProductionBuild,
|
||||||
'__BROWSER__': isBrowserBuild,
|
__BROWSER__: isESMBundlerBuild || isBrowserBuild
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +55,6 @@ function rollupConfig({
|
|||||||
input: 'src/index.ts',
|
input: 'src/index.ts',
|
||||||
output: {
|
output: {
|
||||||
name: 'VueMeta',
|
name: 'VueMeta',
|
||||||
format: 'iife',
|
|
||||||
sourcemap: false,
|
sourcemap: false,
|
||||||
banner,
|
banner,
|
||||||
externalLiveBindings: false,
|
externalLiveBindings: false,
|
||||||
@@ -68,25 +69,25 @@ function rollupConfig({
|
|||||||
commonjs(),
|
commonjs(),
|
||||||
ts({
|
ts({
|
||||||
check: !didTS,
|
check: !didTS,
|
||||||
tsconfig: path.resolve(__dirname, '../tsconfig.json'),
|
tsconfig: r('../tsconfig.json'),
|
||||||
cacheRoot: path.resolve(__dirname, '../node_modules/.rts2_cache'),
|
cacheRoot: r('../node_modules/.rts2_cache'),
|
||||||
tsconfigOverride: {
|
tsconfigOverride: {
|
||||||
compilerOptions: {
|
compilerOptions: {
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
declaration: !didTS,
|
declaration: !didTS,
|
||||||
declarationMap: !didTS,
|
declarationMap: !didTS
|
||||||
},
|
},
|
||||||
exclude: ['node_modules', '__tests__', 'test-dts'],
|
exclude: ['node_modules', '__tests__', 'test-dts']
|
||||||
},
|
}
|
||||||
}),
|
})
|
||||||
].concat(plugins),
|
].concat(plugins)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (isBrowserBuild) {
|
if (isBrowserBuild) {
|
||||||
// remove the ssr renderToString helper for browser builds
|
// remove the ssr renderToString helper for browser builds
|
||||||
thisConfig.plugins.unshift(alias({
|
thisConfig.plugins.unshift(alias({
|
||||||
entries: [
|
entries: [
|
||||||
{ find: '.\/ssr', replacement: path.resolve(__dirname, './stub.js') },
|
{ find: '.\/ssr', replacement: r('./stub.js') }
|
||||||
]
|
]
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -96,8 +97,8 @@ function rollupConfig({
|
|||||||
module: config.output.format === 'es',
|
module: config.output.format === 'es',
|
||||||
compress: {
|
compress: {
|
||||||
ecma: 2015,
|
ecma: 2015,
|
||||||
pure_getters: true,
|
pure_getters: true
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thisConfig.plugins.push(terser(terserOpts))
|
thisConfig.plugins.push(terser(terserOpts))
|
||||||
@@ -113,48 +114,50 @@ export default [
|
|||||||
{
|
{
|
||||||
output: {
|
output: {
|
||||||
file: pkg.unpkg,
|
file: pkg.unpkg,
|
||||||
},
|
format: 'iife'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// minimized umd web build
|
// minimized umd web build
|
||||||
{
|
{
|
||||||
output: {
|
output: {
|
||||||
file: pkg.unpkg.replace('.js', '.min.js'),
|
file: pkg.unpkg.replace('.js', '.min.js'),
|
||||||
},
|
format: 'iife'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// common js build
|
// common js build
|
||||||
{
|
{
|
||||||
output: {
|
output: {
|
||||||
file: pkg.main,
|
file: pkg.main,
|
||||||
format: 'cjs'
|
format: 'cjs'
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
// common js build
|
// common js build
|
||||||
{
|
{
|
||||||
output: {
|
output: {
|
||||||
file: pkg.main.replace('.js', '.prod.js'),
|
file: pkg.main.replace('.js', '.prod.js'),
|
||||||
format: 'cjs'
|
format: 'cjs'
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
// esm build
|
// esm build
|
||||||
{
|
{
|
||||||
output: {
|
output: {
|
||||||
file: pkg.module,
|
file: pkg.module,
|
||||||
format: 'es'
|
format: 'es'
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
// browser esm build
|
// browser esm build
|
||||||
{
|
{
|
||||||
output: {
|
output: {
|
||||||
file: pkg.module.replace('-bundler.js', '-browser.js'),
|
file: pkg.module.replace('-bundler.js', '-browser.js'),
|
||||||
format: 'es'
|
format: 'es'
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
// minimized browser esm build
|
// minimized browser esm build
|
||||||
{
|
{
|
||||||
output: {
|
output: {
|
||||||
file: pkg.module.replace('-bundler.js', '-browser.min.js'),
|
file: pkg.module.replace('-bundler.js', '-browser.min.js'),
|
||||||
format: 'es'
|
format: 'es'
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
// SSR build
|
// SSR build
|
||||||
{
|
{
|
||||||
@@ -162,16 +165,27 @@ export default [
|
|||||||
output: {
|
output: {
|
||||||
file: 'ssr/index.js',
|
file: 'ssr/index.js',
|
||||||
format: 'es'
|
format: 'es'
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
].map(rollupConfig).concat([
|
].map(rollupConfig).concat([
|
||||||
{
|
{
|
||||||
input: path.resolve(__dirname, '../dist/src/index.d.ts'),
|
input: r('../dist/src/index.d.ts'),
|
||||||
output: [{
|
output: [{
|
||||||
file: `dist/${pkg.name}.d.ts`,
|
file: `dist/${pkg.name}.d.ts`,
|
||||||
format: 'es',
|
format: 'es',
|
||||||
|
banner: `${banner}
|
||||||
|
/// <reference path="ssr.d.ts" />
|
||||||
|
`
|
||||||
}],
|
}],
|
||||||
plugins: [dts()],
|
plugins: [dts()]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: r('../dist/src/ssr.d.ts'),
|
||||||
|
output: [{
|
||||||
|
file: `dist/${pkg.name}-ssr.d.ts`,
|
||||||
|
format: 'es'
|
||||||
|
}],
|
||||||
|
plugins: [dts()]
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|||||||
Reference in New Issue
Block a user