2016-08-27 23:03:15 +00:00
|
|
|
const path = require('path')
|
2021-04-06 16:04:48 +00:00
|
|
|
const alias = require('@rollup/plugin-alias')
|
|
|
|
const cjs = require('@rollup/plugin-commonjs')
|
|
|
|
const replace = require('@rollup/plugin-replace')
|
|
|
|
const node = require('@rollup/plugin-node-resolve').nodeResolve
|
2021-04-03 15:36:50 +00:00
|
|
|
const ts = require('rollup-plugin-typescript2')
|
|
|
|
|
2016-08-27 23:03:15 +00:00
|
|
|
const version = process.env.VERSION || require('../package.json').version
|
2019-01-15 21:22:06 +00:00
|
|
|
const featureFlags = require('./feature-flags')
|
2016-08-27 23:03:15 +00:00
|
|
|
|
|
|
|
const banner =
|
|
|
|
'/*!\n' +
|
2018-10-24 16:48:58 +00:00
|
|
|
` * Vue.js v${version}\n` +
|
|
|
|
` * (c) 2014-${new Date().getFullYear()} Evan You\n` +
|
2016-08-27 23:03:15 +00:00
|
|
|
' * Released under the MIT License.\n' +
|
|
|
|
' */'
|
|
|
|
|
2017-04-18 04:37:36 +00:00
|
|
|
const aliases = require('./alias')
|
2022-05-24 00:55:11 +00:00
|
|
|
const resolve = p => {
|
2017-04-18 04:37:36 +00:00
|
|
|
const base = p.split('/')[0]
|
|
|
|
if (aliases[base]) {
|
|
|
|
return path.resolve(aliases[base], p.slice(base.length + 1))
|
|
|
|
} else {
|
|
|
|
return path.resolve(__dirname, '../', p)
|
|
|
|
}
|
|
|
|
}
|
2017-04-16 13:02:58 +00:00
|
|
|
|
2022-06-10 08:35:46 +00:00
|
|
|
// we are bundling forked consolidate.js in compiler-sfc which dynamically
|
|
|
|
// requires a ton of template engines which should be ignored.
|
|
|
|
const consolidatePath = require.resolve('@vue/consolidate/package.json', {
|
|
|
|
paths: [path.resolve(__dirname, '../packages/compiler-sfc')]
|
|
|
|
})
|
|
|
|
|
2016-08-27 23:03:15 +00:00
|
|
|
const builds = {
|
|
|
|
// Runtime only (CommonJS). Used by bundlers e.g. Webpack & Browserify
|
2022-05-31 07:32:44 +00:00
|
|
|
'runtime-cjs-dev': {
|
2021-04-03 15:36:50 +00:00
|
|
|
entry: resolve('web/entry-runtime.ts'),
|
2018-12-05 14:41:16 +00:00
|
|
|
dest: resolve('dist/vue.runtime.common.dev.js'),
|
2016-11-16 21:41:44 +00:00
|
|
|
format: 'cjs',
|
2018-12-05 14:41:16 +00:00
|
|
|
env: 'development',
|
|
|
|
banner
|
|
|
|
},
|
2022-05-31 07:32:44 +00:00
|
|
|
'runtime-cjs-prod': {
|
2021-04-03 15:36:50 +00:00
|
|
|
entry: resolve('web/entry-runtime.ts'),
|
2018-12-05 14:41:16 +00:00
|
|
|
dest: resolve('dist/vue.runtime.common.prod.js'),
|
|
|
|
format: 'cjs',
|
|
|
|
env: 'production',
|
2016-11-16 21:41:44 +00:00
|
|
|
banner
|
|
|
|
},
|
|
|
|
// Runtime+compiler CommonJS build (CommonJS)
|
2022-05-31 07:32:44 +00:00
|
|
|
'full-cjs-dev': {
|
2021-04-03 15:36:50 +00:00
|
|
|
entry: resolve('web/entry-runtime-with-compiler.ts'),
|
2018-12-05 14:41:16 +00:00
|
|
|
dest: resolve('dist/vue.common.dev.js'),
|
2016-10-05 19:16:01 +00:00
|
|
|
format: 'cjs',
|
2018-12-05 14:41:16 +00:00
|
|
|
env: 'development',
|
|
|
|
alias: { he: './entity-decoder' },
|
|
|
|
banner
|
|
|
|
},
|
2022-05-31 07:32:44 +00:00
|
|
|
'full-cjs-prod': {
|
2021-04-03 15:36:50 +00:00
|
|
|
entry: resolve('web/entry-runtime-with-compiler.ts'),
|
2018-12-05 14:41:16 +00:00
|
|
|
dest: resolve('dist/vue.common.prod.js'),
|
|
|
|
format: 'cjs',
|
|
|
|
env: 'production',
|
2016-11-16 21:41:44 +00:00
|
|
|
alias: { he: './entity-decoder' },
|
2016-10-05 19:16:01 +00:00
|
|
|
banner
|
2016-08-27 23:03:15 +00:00
|
|
|
},
|
2019-01-30 14:47:31 +00:00
|
|
|
// Runtime only ES modules build (for bundlers)
|
2022-05-31 07:32:44 +00:00
|
|
|
'runtime-esm': {
|
2022-05-24 13:49:09 +00:00
|
|
|
entry: resolve('web/entry-runtime-esm.ts'),
|
2017-04-16 13:02:58 +00:00
|
|
|
dest: resolve('dist/vue.runtime.esm.js'),
|
2017-02-26 03:09:14 +00:00
|
|
|
format: 'es',
|
|
|
|
banner
|
|
|
|
},
|
2017-11-22 19:23:16 +00:00
|
|
|
// Runtime+compiler ES modules build (for bundlers)
|
2022-05-31 07:32:44 +00:00
|
|
|
'full-esm': {
|
2022-05-24 13:49:09 +00:00
|
|
|
entry: resolve('web/entry-runtime-with-compiler-esm.ts'),
|
2017-04-16 13:02:58 +00:00
|
|
|
dest: resolve('dist/vue.esm.js'),
|
2017-02-26 03:09:14 +00:00
|
|
|
format: 'es',
|
|
|
|
alias: { he: './entity-decoder' },
|
|
|
|
banner
|
|
|
|
},
|
2017-11-22 19:23:16 +00:00
|
|
|
// Runtime+compiler ES modules build (for direct import in browser)
|
2022-05-31 07:32:44 +00:00
|
|
|
'full-esm-browser-dev': {
|
2022-05-24 13:49:09 +00:00
|
|
|
entry: resolve('web/entry-runtime-with-compiler-esm.ts'),
|
2017-11-22 19:23:16 +00:00
|
|
|
dest: resolve('dist/vue.esm.browser.js'),
|
|
|
|
format: 'es',
|
|
|
|
transpile: false,
|
|
|
|
env: 'development',
|
|
|
|
alias: { he: './entity-decoder' },
|
|
|
|
banner
|
|
|
|
},
|
2018-12-05 22:46:28 +00:00
|
|
|
// Runtime+compiler ES modules build (for direct import in browser)
|
2022-05-31 07:32:44 +00:00
|
|
|
'full-esm-browser-prod': {
|
2022-05-24 13:49:09 +00:00
|
|
|
entry: resolve('web/entry-runtime-with-compiler-esm.ts'),
|
2018-12-05 22:46:28 +00:00
|
|
|
dest: resolve('dist/vue.esm.browser.min.js'),
|
|
|
|
format: 'es',
|
|
|
|
transpile: false,
|
|
|
|
env: 'production',
|
|
|
|
alias: { he: './entity-decoder' },
|
|
|
|
banner
|
|
|
|
},
|
2016-11-16 21:41:44 +00:00
|
|
|
// runtime-only build (Browser)
|
2022-05-31 07:32:44 +00:00
|
|
|
'runtime-dev': {
|
2021-04-03 15:36:50 +00:00
|
|
|
entry: resolve('web/entry-runtime.ts'),
|
2017-04-16 13:02:58 +00:00
|
|
|
dest: resolve('dist/vue.runtime.js'),
|
2016-11-01 17:47:55 +00:00
|
|
|
format: 'umd',
|
2016-11-16 16:25:40 +00:00
|
|
|
env: 'development',
|
2016-11-01 17:47:55 +00:00
|
|
|
banner
|
|
|
|
},
|
2016-11-16 21:41:44 +00:00
|
|
|
// runtime-only production build (Browser)
|
2022-05-31 07:32:44 +00:00
|
|
|
'runtime-prod': {
|
2021-04-03 15:36:50 +00:00
|
|
|
entry: resolve('web/entry-runtime.ts'),
|
2017-04-16 13:02:58 +00:00
|
|
|
dest: resolve('dist/vue.runtime.min.js'),
|
2016-08-27 23:03:15 +00:00
|
|
|
format: 'umd',
|
2016-10-05 19:16:01 +00:00
|
|
|
env: 'production',
|
|
|
|
banner
|
2016-08-27 23:03:15 +00:00
|
|
|
},
|
2016-11-16 21:41:44 +00:00
|
|
|
// Runtime+compiler development build (Browser)
|
2022-05-31 07:32:44 +00:00
|
|
|
'full-dev': {
|
2021-04-03 15:36:50 +00:00
|
|
|
entry: resolve('web/entry-runtime-with-compiler.ts'),
|
2017-04-16 13:02:58 +00:00
|
|
|
dest: resolve('dist/vue.js'),
|
2016-08-27 23:03:15 +00:00
|
|
|
format: 'umd',
|
|
|
|
env: 'development',
|
2016-11-16 16:25:40 +00:00
|
|
|
alias: { he: './entity-decoder' },
|
2016-11-05 18:37:30 +00:00
|
|
|
banner
|
2016-08-27 23:03:15 +00:00
|
|
|
},
|
2016-11-16 21:41:44 +00:00
|
|
|
// Runtime+compiler production build (Browser)
|
2022-05-31 07:32:44 +00:00
|
|
|
'full-prod': {
|
2021-04-03 15:36:50 +00:00
|
|
|
entry: resolve('web/entry-runtime-with-compiler.ts'),
|
2017-04-16 13:02:58 +00:00
|
|
|
dest: resolve('dist/vue.min.js'),
|
2016-08-27 23:03:15 +00:00
|
|
|
format: 'umd',
|
|
|
|
env: 'production',
|
2016-11-16 16:25:40 +00:00
|
|
|
alias: { he: './entity-decoder' },
|
2016-11-05 18:37:30 +00:00
|
|
|
banner
|
2016-08-27 23:03:15 +00:00
|
|
|
},
|
|
|
|
// Web compiler (CommonJS).
|
2022-05-31 07:32:44 +00:00
|
|
|
compiler: {
|
2021-04-03 15:36:50 +00:00
|
|
|
entry: resolve('web/entry-compiler.ts'),
|
2022-05-31 07:32:44 +00:00
|
|
|
dest: resolve('packages/template-compiler/build.js'),
|
2016-08-27 23:03:15 +00:00
|
|
|
format: 'cjs',
|
2022-05-19 08:08:46 +00:00
|
|
|
external: Object.keys(
|
2022-05-31 07:32:44 +00:00
|
|
|
require('../packages/template-compiler/package.json').dependencies
|
2022-05-19 08:08:46 +00:00
|
|
|
)
|
2016-08-27 23:03:15 +00:00
|
|
|
},
|
2017-10-02 22:14:41 +00:00
|
|
|
// Web compiler (UMD for in-browser use).
|
2022-05-31 07:32:44 +00:00
|
|
|
'compiler-browser': {
|
2021-04-03 15:36:50 +00:00
|
|
|
entry: resolve('web/entry-compiler.ts'),
|
2022-05-31 07:32:44 +00:00
|
|
|
dest: resolve('packages/template-compiler/browser.js'),
|
2017-10-02 22:14:41 +00:00
|
|
|
format: 'umd',
|
|
|
|
env: 'development',
|
|
|
|
moduleName: 'VueTemplateCompiler',
|
|
|
|
plugins: [node(), cjs()]
|
|
|
|
},
|
2016-08-27 23:03:15 +00:00
|
|
|
// Web server renderer (CommonJS).
|
2022-05-31 07:32:44 +00:00
|
|
|
'server-renderer-dev': {
|
2022-05-31 09:38:27 +00:00
|
|
|
entry: resolve('packages/server-renderer/src/index.ts'),
|
2022-05-31 07:32:44 +00:00
|
|
|
dest: resolve('packages/server-renderer/build.dev.js'),
|
2017-04-16 13:02:58 +00:00
|
|
|
format: 'cjs',
|
2018-12-05 14:41:16 +00:00
|
|
|
env: 'development',
|
2022-05-20 07:26:18 +00:00
|
|
|
external: [
|
|
|
|
'stream',
|
|
|
|
...Object.keys(
|
2022-05-31 07:32:44 +00:00
|
|
|
require('../packages/server-renderer/package.json').dependencies
|
2022-05-20 07:26:18 +00:00
|
|
|
)
|
|
|
|
]
|
2018-12-05 14:41:16 +00:00
|
|
|
},
|
2022-05-31 07:32:44 +00:00
|
|
|
'server-renderer-prod': {
|
2022-05-31 09:38:27 +00:00
|
|
|
entry: resolve('server/index.ts'),
|
2022-05-31 07:32:44 +00:00
|
|
|
dest: resolve('packages/server-renderer/build.prod.js'),
|
2018-12-05 14:41:16 +00:00
|
|
|
format: 'cjs',
|
|
|
|
env: 'production',
|
2022-05-20 07:26:18 +00:00
|
|
|
external: [
|
|
|
|
'stream',
|
|
|
|
...Object.keys(
|
2022-05-31 07:32:44 +00:00
|
|
|
require('../packages/server-renderer/package.json').dependencies
|
2022-05-20 07:26:18 +00:00
|
|
|
)
|
|
|
|
]
|
2017-04-16 13:02:58 +00:00
|
|
|
},
|
2022-05-31 07:32:44 +00:00
|
|
|
'server-renderer-basic': {
|
2022-05-31 09:38:27 +00:00
|
|
|
entry: resolve('server/index-basic.ts'),
|
2022-05-31 07:32:44 +00:00
|
|
|
dest: resolve('packages/server-renderer/basic.js'),
|
2017-06-13 08:54:55 +00:00
|
|
|
format: 'umd',
|
|
|
|
env: 'development',
|
|
|
|
moduleName: 'renderVueComponentToString',
|
|
|
|
plugins: [node(), cjs()]
|
|
|
|
},
|
2022-05-31 07:32:44 +00:00
|
|
|
'server-renderer-webpack-server-plugin': {
|
2021-04-03 15:36:50 +00:00
|
|
|
entry: resolve('server/webpack-plugin/server.ts'),
|
2022-05-31 07:32:44 +00:00
|
|
|
dest: resolve('packages/server-renderer/server-plugin.js'),
|
2017-04-16 13:02:58 +00:00
|
|
|
format: 'cjs',
|
2022-05-19 08:08:46 +00:00
|
|
|
external: Object.keys(
|
2022-05-31 07:32:44 +00:00
|
|
|
require('../packages/server-renderer/package.json').dependencies
|
2022-05-19 08:08:46 +00:00
|
|
|
)
|
2017-04-16 13:02:58 +00:00
|
|
|
},
|
2022-05-31 07:32:44 +00:00
|
|
|
'server-renderer-webpack-client-plugin': {
|
2021-04-03 15:36:50 +00:00
|
|
|
entry: resolve('server/webpack-plugin/client.ts'),
|
2022-05-31 07:32:44 +00:00
|
|
|
dest: resolve('packages/server-renderer/client-plugin.js'),
|
2016-08-27 23:03:15 +00:00
|
|
|
format: 'cjs',
|
2022-05-19 08:08:46 +00:00
|
|
|
external: Object.keys(
|
2022-05-31 07:32:44 +00:00
|
|
|
require('../packages/server-renderer/package.json').dependencies
|
|
|
|
)
|
|
|
|
},
|
|
|
|
'compiler-sfc': {
|
2022-06-10 08:35:46 +00:00
|
|
|
entry: resolve('packages/compiler-sfc/src/index.ts'),
|
2022-05-31 07:32:44 +00:00
|
|
|
dest: resolve('packages/compiler-sfc/dist/compiler-sfc.js'),
|
|
|
|
format: 'cjs',
|
|
|
|
external: Object.keys(
|
|
|
|
require('../packages/compiler-sfc/package.json').dependencies
|
2022-06-10 08:35:46 +00:00
|
|
|
),
|
|
|
|
plugins: [
|
|
|
|
node({ preferBuiltins: true }),
|
|
|
|
cjs({
|
|
|
|
ignore: [
|
|
|
|
...Object.keys(require(consolidatePath).devDependencies),
|
|
|
|
'vm',
|
|
|
|
'crypto',
|
|
|
|
'react-dom/server',
|
|
|
|
'teacup/lib/express',
|
|
|
|
'arc-templates/dist/es5',
|
|
|
|
'then-pug',
|
|
|
|
'then-jade'
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
2016-08-27 23:03:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-19 08:08:46 +00:00
|
|
|
function genConfig(name) {
|
2017-10-04 22:14:53 +00:00
|
|
|
const opts = builds[name]
|
2022-10-11 09:39:59 +00:00
|
|
|
const isTargetingBrowser = !(
|
|
|
|
opts.transpile === false || opts.format === 'cjs'
|
|
|
|
)
|
2021-04-03 15:36:50 +00:00
|
|
|
|
|
|
|
// console.log('__dir', __dirname)
|
2016-08-27 23:03:15 +00:00
|
|
|
const config = {
|
2017-09-27 22:05:39 +00:00
|
|
|
input: opts.entry,
|
2016-08-27 23:03:15 +00:00
|
|
|
external: opts.external,
|
|
|
|
plugins: [
|
2021-04-07 13:02:42 +00:00
|
|
|
alias({
|
|
|
|
entries: Object.assign({}, aliases, opts.alias)
|
|
|
|
}),
|
2021-04-03 15:36:50 +00:00
|
|
|
ts({
|
|
|
|
tsconfig: path.resolve(__dirname, '../', 'tsconfig.json'),
|
2022-05-19 08:08:46 +00:00
|
|
|
cacheRoot: path.resolve(__dirname, '../', 'node_modules/.rts2_cache'),
|
2021-04-03 15:36:50 +00:00
|
|
|
tsconfigOverride: {
|
2022-05-19 08:08:46 +00:00
|
|
|
compilerOptions: {
|
2022-05-23 09:14:02 +00:00
|
|
|
// if targeting browser, target es5
|
|
|
|
// if targeting node, es2017 means Node 8
|
2022-10-11 09:39:59 +00:00
|
|
|
target: isTargetingBrowser ? 'es5' : 'es2017'
|
2022-05-19 08:08:46 +00:00
|
|
|
},
|
2022-10-11 09:39:59 +00:00
|
|
|
include: isTargetingBrowser ? ['src'] : ['src', 'packages/*/src'],
|
2021-04-06 16:04:48 +00:00
|
|
|
exclude: ['test', 'test-dts']
|
2021-04-03 15:36:50 +00:00
|
|
|
}
|
2022-05-19 08:08:46 +00:00
|
|
|
})
|
2017-09-27 22:05:39 +00:00
|
|
|
].concat(opts.plugins || []),
|
|
|
|
output: {
|
|
|
|
file: opts.dest,
|
|
|
|
format: opts.format,
|
|
|
|
banner: opts.banner,
|
2021-04-06 16:04:48 +00:00
|
|
|
name: opts.moduleName || 'Vue',
|
|
|
|
exports: 'auto'
|
2018-10-24 14:41:38 +00:00
|
|
|
},
|
|
|
|
onwarn: (msg, warn) => {
|
|
|
|
if (!/Circular/.test(msg)) {
|
|
|
|
warn(msg)
|
|
|
|
}
|
2017-09-27 22:05:39 +00:00
|
|
|
}
|
2016-08-27 23:03:15 +00:00
|
|
|
}
|
|
|
|
|
2021-04-07 13:02:42 +00:00
|
|
|
// console.log('pluging', config.plugins)
|
|
|
|
|
2019-01-30 14:47:31 +00:00
|
|
|
// built-in vars
|
|
|
|
const vars = {
|
2022-05-25 18:36:51 +00:00
|
|
|
__VERSION__: version,
|
2022-06-15 02:07:42 +00:00
|
|
|
__DEV__: `process.env.NODE_ENV !== 'production'`,
|
2022-06-18 08:09:08 +00:00
|
|
|
__TEST__: false,
|
|
|
|
__GLOBAL__: opts.format === 'umd' || name.includes('browser')
|
2019-01-30 14:47:31 +00:00
|
|
|
}
|
|
|
|
// feature flags
|
2022-05-24 00:55:11 +00:00
|
|
|
Object.keys(featureFlags).forEach(key => {
|
2019-01-30 14:47:31 +00:00
|
|
|
vars[`process.env.${key}`] = featureFlags[key]
|
|
|
|
})
|
|
|
|
// build-specific env
|
2016-08-27 23:03:15 +00:00
|
|
|
if (opts.env) {
|
2019-01-30 14:47:31 +00:00
|
|
|
vars['process.env.NODE_ENV'] = JSON.stringify(opts.env)
|
2022-05-24 00:55:11 +00:00
|
|
|
vars.__DEV__ = opts.env !== 'production'
|
2016-08-27 23:03:15 +00:00
|
|
|
}
|
2021-04-06 16:04:48 +00:00
|
|
|
|
|
|
|
vars.preventAssignment = true
|
2019-01-30 14:47:31 +00:00
|
|
|
config.plugins.push(replace(vars))
|
2016-08-27 23:03:15 +00:00
|
|
|
|
2017-10-04 22:14:53 +00:00
|
|
|
Object.defineProperty(config, '_name', {
|
|
|
|
enumerable: false,
|
|
|
|
value: name
|
|
|
|
})
|
|
|
|
|
2016-08-27 23:03:15 +00:00
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.TARGET) {
|
2017-10-04 22:14:53 +00:00
|
|
|
module.exports = genConfig(process.env.TARGET)
|
2016-08-27 23:03:15 +00:00
|
|
|
} else {
|
2017-10-04 22:14:53 +00:00
|
|
|
exports.getBuild = genConfig
|
|
|
|
exports.getAllBuilds = () => Object.keys(builds).map(genConfig)
|
2016-08-27 23:03:15 +00:00
|
|
|
}
|