Files
form/scripts/getRollupConfig.js
Corbin Crutchley 081a22896e feat: Add Vue adapter (#416)
* chore: initial work at scaffolding Vue package

* chore: initial work on adding in useField and useForm API

* chore: fix build for Vue package

* chore: migrate to slots for functional comps

* chore: got initial fields rendering

* chore: add component names for debuggability

* chore: fix error regarding passdown props

* chore: fix Promise constructor error in demo

* chore: initial work at writing vue store implementation

* feat: add initial useStore and Subscribe instances

* fix: state is now passed as a dedicated reactive option

* chore: temporarily remove Vue 2 typechecking

* chore: make Provider and selector optional

* chore: add createFormFactory

* chore: attempt 1 of test - JSX

* chore: attempt 2 of test - Vue JSX

* chore: attempt 3 of test - H

* chore: migrate to proper h function

* chore: fix tests by bumping package

* chore: fix JSX typings

* chore: add another test for useForm

* chore: listen for fieldAPIs to update

* fix: fields should now update during mount

* chore: add test for useField in Vue

* test: add useField Vue tests

* docs: add early docs for Vue package
2023-09-07 17:20:35 -07:00

241 lines
6.6 KiB
JavaScript

// @ts-check
import { resolve } from 'node:path'
import { babel } from '@rollup/plugin-babel'
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 preserveDirectives from 'rollup-plugin-preserve-directives'
import { rootDir } from './config.js'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import esbuild from 'rollup-plugin-esbuild'
/** @param {'development' | 'production'} type */
const forceEnvPlugin = (type) =>
replace({
'process.env.NODE_ENV': `"${type}"`,
delimiters: ['', ''],
preventAssignment: true,
})
/** @param {'legacy' | 'modern'} type */
const babelPlugin = (type) =>
babel({
configFile: resolve(rootDir, 'babel.config.cjs'),
browserslistConfigFile: type === 'modern' ? true : false,
targets:
type === 'modern'
? ''
: {
chrome: '73',
firefox: '78',
edge: '79',
safari: '12',
ios: '12',
opera: '53',
},
babelHelpers: 'bundled',
exclude: /node_modules/,
extensions: ['.ts', '.tsx'],
})
/**
* @param {Object} opts - Options for building configurations.
* @param {string} opts.name - The name.
* @param {string} opts.outputFile - The output file.
* @param {string} opts.entryFile - The entry file.
* @param {boolean} [opts.bundleDeps] - Flag indicating whether to make all deps external.
* @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) {
return [modernConfig(opts), legacyConfig(opts)]
}
/**
* @param {Object} opts - Options for building configurations.
* @param {string} opts.name - The name.
* @param {string} opts.outputFile - The output file.
* @param {string} opts.entryFile - The entry file.
* @param {boolean} [opts.bundleDeps] - Flag indicating whether to make all deps external.
* @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}
*/
function modernConfig(opts) {
const forceDevEnv = opts.forceDevEnv || false
const forceBundle = opts.forceBundle || false
const bundleDeps = opts.bundleDeps || false
/** @type {import('rollup').OutputOptions[]} */
const bundleOutput = [
{
format: 'esm',
file: `./build/lib/${opts.outputFile}.js`,
sourcemap: true,
},
{
format: 'cjs',
file: `./build/lib/${opts.outputFile}.cjs`,
sourcemap: true,
exports: 'named',
},
]
/** @type {import('rollup').OutputOptions[]} */
const normalOutput = [
{
format: 'esm',
dir: `./build/lib`,
sourcemap: true,
preserveModules: true,
entryFileNames: '[name].js',
},
{
format: 'cjs',
dir: `./build/lib`,
sourcemap: true,
exports: 'named',
preserveModules: true,
entryFileNames: '[name].cjs',
},
]
return {
input: [opts.entryFile],
output: forceBundle ? bundleOutput : normalOutput,
plugins: [
vue({
isProduction: true,
}),
vueJsx({
exclude: [
'./packages/solid-form/**',
'./packages/svelte-form/**',
'./packages/react-form/**',
],
}),
commonJS(),
esbuild({
exclude: [],
loaders: {
'.vue': 'ts',
},
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
}),
babelPlugin('modern'),
nodeResolve({ extensions: ['.ts', '.tsx'] }),
forceDevEnv ? forceEnvPlugin('development') : undefined,
bundleDeps
? undefined
: externals({
packagePath: './package.json',
deps: true,
devDeps: true,
peerDeps: true,
}),
preserveDirectives(),
visualizer({
filename: `./build/stats.html`,
template: 'treemap',
gzipSize: true,
}),
],
}
}
/**
* @param {Object} opts - Options for building configurations.
* @param {string} opts.name - The name.
* @param {string} opts.outputFile - The output file.
* @param {string} opts.entryFile - The entry file.
* @param {boolean} [opts.bundleDeps] - Flag indicating whether to make all deps external.
* @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}
*/
function legacyConfig(opts) {
const forceDevEnv = opts.forceDevEnv || false
const forceBundle = opts.forceBundle || false
const bundleDeps = opts.bundleDeps || false
/** @type {import('rollup').OutputOptions[]} */
const bundleOutput = [
{
format: 'esm',
file: `./build/lib/${opts.outputFile}.legacy.js`,
sourcemap: true,
},
{
format: 'cjs',
file: `./build/lib/${opts.outputFile}.legacy.cjs`,
sourcemap: true,
exports: 'named',
},
]
/** @type {import('rollup').OutputOptions[]} */
const normalOutput = [
{
format: 'esm',
dir: `./build/lib`,
sourcemap: true,
preserveModules: true,
entryFileNames: '[name].legacy.js',
},
{
format: 'cjs',
dir: `./build/lib`,
sourcemap: true,
exports: 'named',
preserveModules: true,
entryFileNames: '[name].legacy.cjs',
},
]
return {
input: [opts.entryFile],
output: forceBundle ? bundleOutput : normalOutput,
plugins: [
vue({
isProduction: true,
}),
vueJsx({
exclude: [
'./packages/solid-form/**',
'./packages/svelte-form/**',
'./packages/react-form/**',
],
}),
commonJS(),
esbuild({
exclude: [],
loaders: {
'.vue': 'ts',
},
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
}),
babelPlugin('legacy'),
nodeResolve({ extensions: ['.ts', '.tsx'] }),
forceDevEnv ? forceEnvPlugin('development') : undefined,
bundleDeps
? undefined
: externals({
packagePath: './package.json',
deps: true,
devDeps: true,
peerDeps: true,
}),
preserveDirectives(),
],
}
}