build: expose compiler-sfc and server-renderer under main vue package + optimize package size

This commit is contained in:
Evan You 2021-09-21 10:26:08 -04:00
parent a42a14d3bc
commit 471f66a1f6
18 changed files with 76 additions and 60 deletions

View File

@ -46,7 +46,8 @@ module.exports = {
moduleNameMapper: {
'@vue/compat': '<rootDir>/packages/vue-compat/src',
'^@vue/(.*?)$': '<rootDir>/packages/$1/src',
vue: '<rootDir>/packages/vue/src'
vue: '<rootDir>/packages/vue/src',
'@vue/consolidate': '@vue/consolidate'
},
rootDir: __dirname,
testMatch: ['<rootDir>/packages/**/__tests__/**/*spec.[jt]s?(x)'],

View File

@ -80,6 +80,9 @@
"serve": "^12.0.0",
"ts-jest": "^27.0.5",
"typescript": "^4.2.2",
"yorkie": "^2.0.0"
"yorkie": "^2.0.0",
"lodash": "^4.17.15",
"marked": "^0.7.0",
"todomvc-app-css": "^2.3.0"
}
}

View File

@ -34,8 +34,10 @@
"dependencies": {
"@vue/shared": "3.2.12",
"@babel/parser": "^7.15.0",
"@babel/types": "^7.15.0",
"estree-walker": "^2.0.2",
"source-map": "^0.6.1"
},
"devDependencies": {
"@babel/types": "^7.15.0"
}
}

View File

@ -33,28 +33,27 @@
"homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-sfc#readme",
"dependencies": {
"@babel/parser": "^7.15.0",
"@types/estree": "^0.0.48",
"@vue/compiler-core": "3.2.12",
"@vue/compiler-dom": "3.2.12",
"@vue/compiler-ssr": "3.2.12",
"@vue/ref-transform": "3.2.12",
"@vue/shared": "3.2.12",
"consolidate": "^0.16.0",
"estree-walker": "^2.0.2",
"hash-sum": "^2.0.0",
"lru-cache": "^5.1.1",
"magic-string": "^0.25.7",
"merge-source-map": "^1.1.0",
"postcss": "^8.1.10",
"postcss-modules": "^4.0.0",
"postcss-selector-parser": "^6.0.4",
"source-map": "^0.6.1"
"source-map": "^0.6.1",
"postcss": "^8.1.10"
},
"devDependencies": {
"@types/estree": "^0.0.48",
"@babel/types": "^7.15.0",
"@types/consolidate": "^0.14.0",
"@types/lru-cache": "^5.1.0",
"pug": "^3.0.1",
"sass": "^1.26.9"
"sass": "^1.26.9",
"@vue/consolidate": "^0.17.2",
"hash-sum": "^2.0.0",
"lru-cache": "^5.1.1",
"merge-source-map": "^1.1.0",
"postcss-modules": "^4.0.0",
"postcss-selector-parser": "^6.0.4"
}
}

View File

@ -1,5 +1,7 @@
import LRU from 'lru-cache'
export function createCache<T>(size = 500) {
return __GLOBAL__ || __ESM_BROWSER__
? new Map<string, T>()
: (new (require('lru-cache'))(size) as Map<string, T>)
: (new LRU(size) as any as Map<string, T>)
}

View File

@ -15,6 +15,7 @@ import {
} from './stylePreprocessors'
import { RawSourceMap } from 'source-map'
import { cssVarsPlugin } from './cssVars'
import postcssModules from 'postcss-modules'
export interface SFCStyleCompileOptions {
source: string
@ -47,7 +48,7 @@ export interface CSSModulesOptions {
hashPrefix?: string
localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly'
exportGlobals?: boolean
globalModulePaths?: string[]
globalModulePaths?: RegExp[]
}
export interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions {
@ -131,7 +132,7 @@ export function doCompileStyle(
)
}
plugins.push(
require('postcss-modules')({
postcssModules({
...modulesOptions,
getJSON: (_cssFileName: string, json: Record<string, string>) => {
cssModules = json

View File

@ -21,7 +21,7 @@ import {
import { generateCodeFrame, isObject } from '@vue/shared'
import * as CompilerDOM from '@vue/compiler-dom'
import * as CompilerSSR from '@vue/compiler-ssr'
import consolidate from 'consolidate'
import consolidate from '@vue/consolidate'
import { warnOnce } from './warn'
import { genCssVarsFromList } from './cssVars'
@ -121,7 +121,7 @@ export function compileTemplate(
? preprocessCustomRequire(preprocessLang)
: __ESM_BROWSER__
? undefined
: require('consolidate')[preprocessLang as keyof typeof consolidate]
: consolidate[preprocessLang as keyof typeof consolidate]
: false
if (preprocessor) {
try {

1
packages/vue/compiler-sfc/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export * from '@vue/compiler-sfc'

View File

@ -0,0 +1 @@
module.exports = require('@vue/compiler-sfc')

View File

@ -0,0 +1 @@
export * from '@vue/compiler-sfc'

View File

@ -0,0 +1,5 @@
{
"main": "index.js",
"module": "index.mjs",
"types": "index.d.ts"
}

View File

@ -10,6 +10,8 @@
"files": [
"index.js",
"dist",
"compiler-sfc",
"server-renderer",
"ref-macros.d.ts"
],
"buildOptions": {
@ -40,11 +42,8 @@
"dependencies": {
"@vue/shared": "3.2.12",
"@vue/compiler-dom": "3.2.12",
"@vue/runtime-dom": "3.2.12"
},
"devDependencies": {
"lodash": "^4.17.15",
"marked": "^0.7.0",
"todomvc-app-css": "^2.3.0"
"@vue/runtime-dom": "3.2.12",
"@vue/compiler-sfc": "3.2.12",
"@vue/server-renderer": "3.2.12"
}
}

View File

@ -0,0 +1 @@
export * from '@vue/server-renderer'

View File

@ -0,0 +1 @@
module.exports = require('@vue/server-renderer')

View File

@ -0,0 +1 @@
export * from '@vue/server-renderer'

View File

@ -0,0 +1,5 @@
{
"main": "index.js",
"module": "index.mjs",
"types": "index.d.ts"
}

View File

@ -36,7 +36,6 @@ const outputConfigs = {
file: resolve(`dist/${name}.global.js`),
format: `iife`
},
// runtime-only builds, for main "vue" package only
'esm-bundler-runtime': {
file: resolve(`dist/${name}.runtime.esm-bundler.js`),
@ -140,7 +139,7 @@ function createConfig(format, output, plugins = []) {
}
} else {
// Node / esm-bundler builds.
// externalize all deps unless it's the compat build.
// externalize all direct deps unless it's the compat build.
external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
@ -148,21 +147,35 @@ function createConfig(format, output, plugins = []) {
]
}
// the browser builds of @vue/compiler-sfc requires postcss to be available
// as a global (e.g. http://wzrd.in/standalone/postcss)
output.globals = {
postcss: 'postcss'
// we are bundling forked consolidate.js in compiler-sfc which dynamically
// requires a ton of template engines which should be ignored.
let cjsIgnores = []
if (pkg.name === '@vue/compiler-sfc') {
cjsIgnores = [
...Object.keys(require('@vue/consolidate/package.json').devDependencies),
'vm',
'crypto',
'react-dom/server',
'teacup/lib/express',
'arc-templates/dist/es5',
'then-pug',
'then-jade'
]
}
const nodePlugins =
packageOptions.enableNonBrowserBranches && format !== 'cjs'
(format === 'cjs' && Object.keys(pkg.devDependencies || {}).length) ||
packageOptions.enableNonBrowserBranches
? [
// @ts-ignore
require('@rollup/plugin-commonjs')({
sourceMap: false
sourceMap: false,
ignore: cjsIgnores
}),
// @ts-ignore
require('rollup-plugin-polyfill-node')(),
...(format === 'cjs'
? []
: // @ts-ignore
[require('rollup-plugin-polyfill-node')()]),
require('@rollup/plugin-node-resolve').nodeResolve()
]
: []

View File

@ -739,19 +739,6 @@
dependencies:
"@babel/types" "^7.3.0"
"@types/bluebird@*":
version "3.5.36"
resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.36.tgz#00d9301d4dc35c2f6465a8aec634bb533674c652"
integrity sha512-HBNx4lhkxN7bx6P0++W8E289foSu8kO8GCk2unhuVggO+cE7rh9DhZUyPhUxNRG9m+5B5BTKxZQ5ZP92x/mx9Q==
"@types/consolidate@^0.14.0":
version "0.14.1"
resolved "https://registry.yarnpkg.com/@types/consolidate/-/consolidate-0.14.1.tgz#78f01b1ed747d945dea9969581fcc1d0cb59bad8"
integrity sha512-p0QTiPgjYssVJEo8zJ1WPfvfCpSvIU9oLZ7WPKl4Nx5dvaRAGb7Mk0a14T6UOVhI5PXYL7CkM4+lS7VRrUePUQ==
dependencies:
"@types/bluebird" "*"
"@types/node" "*"
"@types/estree@*":
version "0.0.50"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.50.tgz#1e0caa9364d3fccd2931c3ed96fdbeaa5d4cca83"
@ -928,6 +915,11 @@
resolved "https://registry.yarnpkg.com/@vitejs/plugin-vue/-/plugin-vue-1.8.1.tgz#6cc2a8dfd04201e3c868c239091aaa89aa75f880"
integrity sha512-gktQGZ7qfaDdVJhT86fWSkyhP+bdoA81f5S2TQOL5Sbe5q7B36XfLGq8Q0BpHoqhPSflAMe6WwM1IecP1sChRw==
"@vue/consolidate@^0.17.2":
version "0.17.2"
resolved "https://registry.yarnpkg.com/@vue/consolidate/-/consolidate-0.17.2.tgz#8a871a638ae94fd88660a235b7b0837538b92e35"
integrity sha512-OG4/GJDOJdERTBw7G/gXE1Xf0cbPEBGJ73sBe7pOeMR4A0x3JNjKuwcv7QjXSOsWiYtsqDDgaKFac9fj1Gv1fw==
"@vue/repl@^0.3.7":
version "0.3.7"
resolved "https://registry.yarnpkg.com/@vue/repl/-/repl-0.3.7.tgz#e5bd0f4a87ce1ce88bc03a09ec1bb5ccec779bce"
@ -1266,11 +1258,6 @@ bl@~0.8.1:
dependencies:
readable-stream "~1.0.26"
bluebird@^3.7.2:
version "3.7.2"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.9:
version "4.12.0"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88"
@ -1732,13 +1719,6 @@ concat-stream@^1.4.4:
readable-stream "^2.2.2"
typedarray "^0.0.6"
consolidate@^0.16.0:
version "0.16.0"
resolved "https://registry.yarnpkg.com/consolidate/-/consolidate-0.16.0.tgz#a11864768930f2f19431660a65906668f5fbdc16"
integrity sha512-Nhl1wzCslqXYTJVDyJCu3ODohy9OfBMB5uD2BiBTzd7w+QY0lBzafkR8y8755yMYHAaMD4NuzbAw03/xzfw+eQ==
dependencies:
bluebird "^3.7.2"
constantinople@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/constantinople/-/constantinople-4.0.1.tgz#0def113fa0e4dc8de83331a5cf79c8b325213151"