|
@ -1,16 +1,29 @@ |
|
|
// @ts-check |
|
|
// @ts-check |
|
|
|
|
|
import { createRequire } from 'module' |
|
|
|
|
|
import { fileURLToPath } from 'url' |
|
|
import path from 'path' |
|
|
import path from 'path' |
|
|
import ts from 'rollup-plugin-typescript2' |
|
|
import ts from 'rollup-plugin-typescript2' |
|
|
import replace from '@rollup/plugin-replace' |
|
|
import replace from '@rollup/plugin-replace' |
|
|
import json from '@rollup/plugin-json' |
|
|
import json from '@rollup/plugin-json' |
|
|
|
|
|
import chalk from 'chalk' |
|
|
|
|
|
import commonJS from '@rollup/plugin-commonjs' |
|
|
|
|
|
import polyfillNode from 'rollup-plugin-polyfill-node' |
|
|
|
|
|
import { nodeResolve } from '@rollup/plugin-node-resolve' |
|
|
|
|
|
import { terser } from 'rollup-plugin-terser' |
|
|
|
|
|
|
|
|
if (!process.env.TARGET) { |
|
|
if (!process.env.TARGET) { |
|
|
throw new Error('TARGET package must be specified via --environment flag.') |
|
|
throw new Error('TARGET package must be specified via --environment flag.') |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const require = createRequire(import.meta.url) |
|
|
|
|
|
const __dirname = fileURLToPath(new URL('.', import.meta.url)) |
|
|
|
|
|
|
|
|
const masterVersion = require('./package.json').version |
|
|
const masterVersion = require('./package.json').version |
|
|
|
|
|
const consolidatePkg = require('@vue/consolidate/package.json') |
|
|
|
|
|
|
|
|
const packagesDir = path.resolve(__dirname, 'packages') |
|
|
const packagesDir = path.resolve(__dirname, 'packages') |
|
|
const packageDir = path.resolve(packagesDir, process.env.TARGET) |
|
|
const packageDir = path.resolve(packagesDir, process.env.TARGET) |
|
|
|
|
|
|
|
|
const resolve = p => path.resolve(packageDir, p) |
|
|
const resolve = p => path.resolve(packageDir, p) |
|
|
const pkg = require(resolve(`package.json`)) |
|
|
const pkg = require(resolve(`package.json`)) |
|
|
const packageOptions = pkg.buildOptions || {} |
|
|
const packageOptions = pkg.buildOptions || {} |
|
@ -76,7 +89,7 @@ export default packageConfigs |
|
|
|
|
|
|
|
|
function createConfig(format, output, plugins = []) { |
|
|
function createConfig(format, output, plugins = []) { |
|
|
if (!output) { |
|
|
if (!output) { |
|
|
console.log(require('chalk').yellow(`invalid format: "${format}"`)) |
|
|
|
|
|
|
|
|
console.log(chalk.yellow(`invalid format: "${format}"`)) |
|
|
process.exit(1) |
|
|
process.exit(1) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -153,11 +166,8 @@ function createConfig(format, output, plugins = []) { |
|
|
// requires a ton of template engines which should be ignored. |
|
|
// requires a ton of template engines which should be ignored. |
|
|
let cjsIgnores = [] |
|
|
let cjsIgnores = [] |
|
|
if (pkg.name === '@vue/compiler-sfc') { |
|
|
if (pkg.name === '@vue/compiler-sfc') { |
|
|
const consolidatePath = require.resolve('@vue/consolidate/package.json', { |
|
|
|
|
|
paths: [packageDir] |
|
|
|
|
|
}) |
|
|
|
|
|
cjsIgnores = [ |
|
|
cjsIgnores = [ |
|
|
...Object.keys(require(consolidatePath).devDependencies), |
|
|
|
|
|
|
|
|
...Object.keys(consolidatePkg.devDependencies), |
|
|
'vm', |
|
|
'vm', |
|
|
'crypto', |
|
|
'crypto', |
|
|
'react-dom/server', |
|
|
'react-dom/server', |
|
@ -172,16 +182,12 @@ function createConfig(format, output, plugins = []) { |
|
|
(format === 'cjs' && Object.keys(pkg.devDependencies || {}).length) || |
|
|
(format === 'cjs' && Object.keys(pkg.devDependencies || {}).length) || |
|
|
packageOptions.enableNonBrowserBranches |
|
|
packageOptions.enableNonBrowserBranches |
|
|
? [ |
|
|
? [ |
|
|
// @ts-ignore |
|
|
|
|
|
require('@rollup/plugin-commonjs')({ |
|
|
|
|
|
|
|
|
commonJS({ |
|
|
sourceMap: false, |
|
|
sourceMap: false, |
|
|
ignore: cjsIgnores |
|
|
ignore: cjsIgnores |
|
|
}), |
|
|
}), |
|
|
...(format === 'cjs' |
|
|
|
|
|
? [] |
|
|
|
|
|
: // @ts-ignore |
|
|
|
|
|
[require('rollup-plugin-polyfill-node')()]), |
|
|
|
|
|
require('@rollup/plugin-node-resolve').nodeResolve() |
|
|
|
|
|
|
|
|
...(format === 'cjs' ? [] : [polyfillNode()]), |
|
|
|
|
|
nodeResolve() |
|
|
] |
|
|
] |
|
|
: [] |
|
|
: [] |
|
|
|
|
|
|
|
@ -301,7 +307,6 @@ function createProductionConfig(format) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function createMinifiedConfig(format) { |
|
|
function createMinifiedConfig(format) { |
|
|
const { terser } = require('rollup-plugin-terser') |
|
|
|
|
|
return createConfig( |
|
|
return createConfig( |
|
|
format, |
|
|
format, |
|
|
{ |
|
|
{ |