提交 9e9456bb 编写于 作者: fxy060608's avatar fxy060608

build(deps): bump vite from 1.0.0-rc.13 to 2.0.0-beta.4

上级 3001efa9
......@@ -4,14 +4,14 @@ const NodeGlobals = ['module', 'require']
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module'
sourceType: 'module',
},
rules: {
'no-unused-vars': [
'error',
// we are only using this rule to check for unused arguments since TS
// catches unused variables but not args.
{ varsIgnorePattern: '.*', args: 'after-used', argsIgnorePattern: '^_' }
{ varsIgnorePattern: '.*', args: 'after-used', argsIgnorePattern: '^_' },
],
// most of the codebase are expected to be env agnostic
'no-restricted-globals': ['error', ...DOMGlobals, ...NodeGlobals],
......@@ -20,8 +20,8 @@ module.exports = {
'no-restricted-syntax': [
'error',
'ObjectExpression > SpreadElement',
'ObjectPattern > RestElement'
]
'ObjectPattern > RestElement',
],
},
overrides: [
// tests, no restrictions (runs in Node / jest with jsdom)
......@@ -29,28 +29,28 @@ module.exports = {
files: ['**/__tests__/**'],
rules: {
'no-restricted-globals': 'off',
'no-restricted-syntax': 'off'
}
'no-restricted-syntax': 'off',
},
},
// Packages targeting DOM
{
files: [
'packages/{uni-components,uni-h5,uni-h5-vue,uni-shared,uni-core}/**'
'packages/{uni-components,uni-h5,uni-h5-vue,uni-shared,uni-core}/**',
],
rules: {
'no-restricted-globals': ['error', ...NodeGlobals]
}
'no-restricted-globals': ['error', ...NodeGlobals],
},
},
// Packages targeting Node
{
files: [
'packages/{vue-cli-plugin-uni,vue-cli-plugin-hbuilderx}/**',
'packages/*/vite.config.ts'
'packages/{vue-cli-plugin-uni,vue-cli-plugin-hbuilderx,vite-plugin-uni}/**',
'packages/*/vite.config.ts',
],
rules: {
'no-restricted-globals': ['error', ...DOMGlobals],
'no-restricted-syntax': 'off'
}
}
]
'no-restricted-syntax': 'off',
},
},
],
}
......@@ -5,7 +5,6 @@
"packages/*"
],
"scripts": {
"dev": "node scripts/dev.js",
"build": "node scripts/build.js",
"lint": "eslint packages/**/*.ts",
"format": "prettier --write --parser typescript \"packages/**/*.ts?(x)\"",
......@@ -34,41 +33,42 @@
"node": ">=10.0.0"
},
"devDependencies": {
"@dcloudio/types": "^2.0.0",
"@ls-lint/ls-lint": "^1.8.0",
"@microsoft/api-extractor": "^7.3.9",
"@dcloudio/types": "^2.0.20",
"@ls-lint/ls-lint": "^1.9.2",
"@microsoft/api-extractor": "^7.12.1",
"@rollup/plugin-alias": "^3.1.1",
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-json": "^4.0.0",
"@rollup/plugin-node-resolve": "^8.0.0",
"@rollup/plugin-replace": "^2.2.1",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"@rollup/plugin-replace": "^2.3.4",
"@types/debug": "^4.1.5",
"@types/fs-extra": "^9.0.5",
"@types/jest": "^26.0.0",
"@types/node": "13.11.1",
"@types/puppeteer": "^2.0.0",
"@typescript-eslint/parser": "^3.2.0",
"@vue/compiler-sfc": "^3.0.0-rc.9",
"@types/fs-extra": "^9.0.6",
"@types/jest": "^26.0.19",
"@types/node": "^14.14.20",
"@types/puppeteer": "^5.4.2",
"@typescript-eslint/parser": "^4.12.0",
"@vitejs/plugin-vue": "^1.0.4",
"@vue/compiler-sfc": "^3.0.5",
"brotli": "^1.3.2",
"eslint": "^7.2.0",
"eslint": "^7.17.0",
"fs-extra": "^9.0.1",
"jest": "^26.0.1",
"lint-staged": "^10.2.10",
"mini-types": "^0.1.3",
"miniprogram-api-typings": "^2.11.0-1",
"prettier": "~1.14.0",
"puppeteer": "^2.0.0",
"rollup": "^2.16.1",
"jest": "^26.6.3",
"lint-staged": "^10.5.3",
"mini-types": "^0.1.4",
"miniprogram-api-typings": "^3.2.0",
"prettier": "^2.2.1",
"puppeteer": "^5.5.0",
"rollup": "^2.35.1",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-terser": "^6.1.0",
"rollup-plugin-typescript2": "^0.27.1",
"rollup-plugin-vue": "^6.0.0-beta.10",
"semver": "^7.3.2",
"ts-jest": "^26.1.0",
"typescript": "^3.9.3",
"vite": "^1.0.0-rc.13",
"vue": "^3.0.3",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.29.0",
"rollup-plugin-vue": "^6.0.0",
"semver": "^7.3.4",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3",
"vite": "^2.0.0-beta.4",
"vue": "3.0.5",
"yorkie": "^2.0.0"
}
}
import fs from 'fs'
import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { isCustomElement } from '../uni-shared'
export default {
export default defineConfig({
root: '.',
minify: false,
assetsDir: '.',
emitAssets: false,
define: {
__PLATFORM__: JSON.stringify('app-plus')
__PLATFORM__: JSON.stringify('app-plus'),
},
vueCompilerOptions: {
isCustomElement
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement,
},
},
}),
],
build: {
minify: false,
assetsDir: '.',
rollupOptions: {
input: 'src/index.ts',
external: ['vue', '@vue/shared', '@dcloudio/uni-shared'],
preserveEntrySignatures: 'strict',
output: {
format: 'es',
entryFileNames: 'uni-components.esm.js',
assetFileNames(assetInfo) {
if (assetInfo.name === 'style.css') {
return 'uni-components.css'
}
return 'assets/[name]-[hash][extname]'
},
},
},
// emitAssets: false,
},
rollupInputOptions: {
input: 'src/index.ts',
external: ['vue', '@vue/shared', '@dcloudio/uni-shared'],
preserveEntrySignatures: 'strict'
},
rollupOutputOptions: {
format: 'es',
entryFileNames: 'uni-components.esm.js',
assetFileNames(assetInfo) {
if (assetInfo.name === 'style.css') {
return 'uni-components.css'
}
return 'assets/[name]-[hash][extname]'
}
}
}
})
import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import replace from '@rollup/plugin-replace'
import { isCustomElement } from '../uni-shared'
......@@ -8,43 +11,62 @@ function resolve(file: string) {
return path.resolve(__dirname, file)
}
export default {
export default defineConfig({
root: '.',
minify: false,
assetsDir: '.',
emitAssets: false,
alias: {
'@dcloudio/uni-api': resolve('../uni-api/src/index.ts'),
'@dcloudio/uni-vue': resolve('../uni-vue/src/index.ts'),
'@dcloudio/uni-core': resolve('../uni-core/src/index.ts'),
'@dcloudio/uni-components': resolve('../uni-components/src/index.ts')
},
define: {
global: 'window',
__DEV__: `(process.env.NODE_ENV !== 'production')`,
__PLATFORM__: JSON.stringify('h5')
__PLATFORM__: JSON.stringify('h5'),
},
vueCompilerOptions: {
isCustomElement
alias: [
{
find: '@dcloudio/uni-api',
replacement: resolve('../uni-api/src/index.ts'),
},
{
find: '@dcloudio/uni-vue',
replacement: resolve('../uni-vue/src/index.ts'),
},
{
find: '@dcloudio/uni-core',
replacement: resolve('../uni-core/src/index.ts'),
},
{
find: '@dcloudio/uni-components',
replacement: resolve('../uni-components/src/index.ts'),
},
],
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement,
},
},
}),
],
build: {
minify: false,
assetsDir: '.',
rollupOptions: {
input: 'src/index.ts',
external: ['vue', 'vue-router', '@vue/shared', '@dcloudio/uni-shared'],
preserveEntrySignatures: 'strict',
plugins: [
replace({
createApi: `/*#__PURE__*/ createApi`,
}),
],
output: {
format: 'es',
entryFileNames: 'uni-h5.esm.js',
assetFileNames(assetInfo) {
if (assetInfo.name === 'style.css') {
return 'uni-h5.css'
}
return 'assets/[name]-[hash][extname]'
},
},
},
},
rollupInputOptions: {
input: 'src/index.ts',
external: ['vue', 'vue-router', '@vue/shared', '@dcloudio/uni-shared'],
preserveEntrySignatures: 'strict',
plugins: [
replace({
createApi: `/*#__PURE__*/ createApi`
})
]
},
rollupOutputOptions: {
format: 'es',
entryFileNames: 'uni-h5.esm.js',
assetFileNames(assetInfo) {
if (assetInfo.name === 'style.css') {
return 'uni-h5.css'
}
return 'assets/[name]-[hash][extname]'
}
}
}
})
......@@ -3247,7 +3247,7 @@ function defineEmit() {
}
// Core API ------------------------------------------------------------------
const version = "3.0.4";
const version = "3.0.5";
// import deepCopy from './deepCopy'
/**
......
......@@ -22,12 +22,13 @@
"license": "Apache-2.0",
"dependencies": {
"@rollup/pluginutils": "^4.1.0",
"debug": "^4.3.1",
"estree-walker": "^2.0.1",
"fs-extra": "^9.0.1",
"magic-string": "^0.25.7"
},
"peerDependencies": {
"@dcloudio/uni-cli-shared": "^3.0.0",
"vite": "^1.0.0-rc.13"
"vite": "^2.0.0-beta.4"
}
}
......@@ -5,7 +5,7 @@ import { vueCompilerOptions } from '@dcloudio/uni-cli-shared'
import {
serverPluginEnv,
serverPluginMainJs,
serverPluginPagesJson
serverPluginPagesJson,
} from './server'
import {
......@@ -13,19 +13,18 @@ import {
buildPluginInject,
buildPluginMainJs,
buildPluginPagesJson,
buildPluginDynamicImport
buildPluginDynamicImport,
} from './build'
import { dynamicImportCode } from './utils/dynamicImportUtils'
import { initEasycoms } from './utils/easycomUtils'
import { initEasycoms, dynamicImportCode, transform } from './utils'
const VUES = ['vue', 'vue.js', './vue.js']
const VUES = ['vue', 'vue.js', './vue.js', 'dist/vue.runtime.esm-bundler.js']
const plugins = [
buildPluginMainJs,
buildPluginPagesJson,
buildPluginInject,
buildPluginCopy
buildPluginCopy,
]
if (dynamicImportCode) {
......@@ -33,49 +32,56 @@ if (dynamicImportCode) {
}
const plugin: Plugin = {
define: {
__UNI_WX_API__: true,
__UNI_WXS_API__: true,
__UNI_ROUTER_MODE__: JSON.stringify('hash')
},
resolvers: [
{
alias(id: string) {
if (VUES.includes(id)) {
return '@dcloudio/uni-h5-vue'
}
if (id.startsWith('@/')) {
return id.replace('@/', '/src/')
}
}
}
],
configureServer: [serverPluginEnv, serverPluginMainJs, serverPluginPagesJson],
rollupInputOptions: {
plugins
plugins,
},
vueCompilerOptions,
configureBuild({ root }) {
initEasycoms(root)
}
},
}
// TODO 等待 vite 升级支持以下配置
Object.assign(plugin, {
optimizeDeps: {
exclude: [
'vue',
'vue-router',
'@dcloudio/uni-h5',
'@dcloudio/uni-h5-vue',
'@dcloudio/uni-shared'
]
'@dcloudio/uni-shared',
],
},
chokidarWatchOptions: {
ignored: [
'**/node_modules/**',
'**/.git/**',
'**/uniCloud-aliyun/**',
'**/uniCloud-tcb/**'
]
}
'**/uniCloud-tcb/**',
],
},
})
export default plugin
interface Options {}
export default function uniPlugin(_rawOptions: Options = {}): Plugin {
return {
name: 'vite:uni',
config(config) {
config.define = {
__UNI_WX_API__: true,
__UNI_WXS_API__: true,
__UNI_ROUTER_MODE__: JSON.stringify('hash'),
...config.define,
}
},
async resolveId(id) {
if (VUES.includes(id)) {
return '@dcloudio/uni-h5-vue'
}
if (id.startsWith('@/')) {
return id.replace('@/', '/src/')
}
},
transform,
configureServer() {},
}
}
export * from './serverPluginEnv'
export * from './serverPluginMainJs'
export * from './serverPluginPagesJson'
export * from './serveEasycom'
export * from './serveMainJs'
export * from './servePagesJson'
import { ViteDevServer } from 'vite'
import { initEasycoms } from '../utils'
export const serveEasycom = (server: ViteDevServer) => {
const { dirs, refresh } = initEasycoms(server.config.root)
server.watcher.on('all', (eventName, path) => {
if (!['add', 'unlink'].includes(eventName)) {
return
}
if (dirs.find((dir) => path.startsWith(dir))) {
refresh()
}
})
}
import path from 'path'
import { ServerPlugin, readBody } from 'vite'
import { readBody, ViteDevServer } from 'vite'
import { getRoot, isMainJs, wrapperMainCode } from '../utils'
export const serverPluginMainJs: ServerPlugin = ({ app, root }) => {
app.use(async (ctx, next) => {
export const serveMainJs = (server: ViteDevServer) => {
server.app.use(async (ctx, next) => {
await next()
if (isMainJs(ctx.path)) {
const body = await readBody(ctx.body)
......
import { ServerPlugin, readBody } from 'vite'
import { ViteDevServer } from 'vite'
import { parsePagesJson } from '../utils'
......@@ -10,8 +10,8 @@ window.UniViewJSBridge = UniViewJSBridge
window.UniServiceJSBridge = UniServiceJSBridge
`
export const serverPluginPagesJson: ServerPlugin = ({ app }) => {
app.use(async (ctx, next) => {
export const servePagesJson = (server: ViteDevServer) => {
server.app.use(async (ctx, next) => {
const isPagesJson = ctx.path.endsWith('pages.json')
if (isPagesJson) {
//skip serverPluginJson
......
import { ServerPlugin } from 'vite'
import { initEasycoms } from '../utils/easycomUtils'
export const serverPluginEnv: ServerPlugin = ({ root, watcher }) => {
const { dirs, refresh } = initEasycoms(root)
watcher.on('all', (eventName, path) => {
if (!['add', 'unlink'].includes(eventName)) {
return
}
if (dirs.find(dir => path.startsWith(dir))) {
refresh()
}
})
}
......@@ -4,13 +4,13 @@ import { initEasycom } from '@dcloudio/uni-cli-shared'
export function initEasycoms(root: string) {
const rootDir = path.resolve(root, 'src')
const dirs = ['components'].map(dir => path.resolve(rootDir, dir))
const dirs = ['components'].map((dir) => path.resolve(rootDir, dir))
const easycomOptions = { dirs, rootDir: rootDir }
initEasycom(easycomOptions)
return {
dirs,
refresh() {
initEasycom(easycomOptions)
}
},
}
}
export * from './mainJsUtils'
export * from './pagesJsonUtils'
export * from './dynamicImportUtils'
export * from './mainJs'
export * from './easycom'
export * from './transform'
export * from './pagesJson'
export * from './dynamicImport'
import path from 'path'
import slash from 'slash'
import { dynamicImportCode } from './dynamicImportUtils'
import { dynamicImportCode } from './dynamicImport'
const MAIN_RE = /main.[jt]s/
......
......@@ -46,7 +46,7 @@ function formatPages(pagesJson: Record<string, any>, jsonStr: string) {
function removePlatformStyle(globalStyle: Record<string, any>) {
delete globalStyle['app-plus']
delete globalStyle['h5']
Object.keys(globalStyle).forEach(name => {
Object.keys(globalStyle).forEach((name) => {
if (name.startsWith('mp-') || name.startsWith('quickapp')) {
delete globalStyle[name]
}
......@@ -85,7 +85,7 @@ function formatSubpackages(subpackages: SubpackagesOptions[]) {
function formatPagesJson(jsonStr: string) {
let pagesJson: Record<string, any> = {
pages: []
pages: [],
}
//TODO preprocess
try {
......@@ -116,14 +116,14 @@ function generatePageDefineCode(pageOptions: PageOptions) {
function generatePagesDefineCode(pagesJson: Record<string, any>) {
return (pagesJson.pages as PageOptions[])
.map(pageOptions => generatePageDefineCode(pageOptions))
.map((pageOptions) => generatePageDefineCode(pageOptions))
.join('\n')
}
function formatPagesRoute(pagesJson: Record<string, any>): PageRouteOptions[] {
const firstPagePath = pagesJson.pages[0].path
const tabBarList = (pagesJson.tabBar && pagesJson.tabBar.list) || []
return (pagesJson.pages as PageOptions[]).map(pageOptions => {
return (pagesJson.pages as PageOptions[]).map((pageOptions) => {
const path = pageOptions.path
const name = formatPageIdentifier(path)
const isEntry = firstPagePath === path ? true : undefined
......@@ -142,14 +142,14 @@ function formatPagesRoute(pagesJson: Record<string, any>): PageRouteOptions[] {
windowTop,
topWindow: props.topWindow,
leftWindow: props.leftWindow,
rightWindow: props.rightWindow
rightWindow: props.rightWindow,
}
Object.assign(props, meta)
return {
name,
path: pageOptions.path,
props,
meta
meta,
}
})
}
......@@ -169,13 +169,13 @@ function generatePageRoute({ name, path, props, meta }: PageRouteOptions) {
}
function generatePagesRoute(pagesRouteOptions: PageRouteOptions[]) {
return pagesRouteOptions.map(pageOptions => generatePageRoute(pageOptions))
return pagesRouteOptions.map((pageOptions) => generatePageRoute(pageOptions))
}
function generateRoutes(pagesJson: Record<string, any>) {
return [
`{ path: '/${pagesJson.pages[0].path}', redirect: '/' }`,
...generatePagesRoute(formatPagesRoute(pagesJson))
...generatePagesRoute(formatPagesRoute(pagesJson)),
]
}
......
import path from 'path'
import debug from 'debug'
import { TransformHook } from 'rollup'
const debugPre = debug('uni:pre')
const extensions = ['.vue', '.nvue', '.js', '.json', '.css']
export const transform: TransformHook = (code, id) => {
const extname = path.extname(id)
if (!extensions.includes(extname)) {
return
}
// TODO
debugPre(id)
return code
}
......@@ -59,17 +59,21 @@ async function build(target) {
'vite',
['build', '--config', path.resolve(pkgDir, 'vite.config.ts')],
{
stdio: 'inherit'
stdio: 'inherit',
}
)
} else if (bundler === 'tsc') {
return await execa(
'tsc',
['--listEmittedFiles', types ? `--declaration` : '', '-p', pkgDir],
{
stdio: 'inherit'
}
)
const args = [
'--listEmittedFiles',
'-p',
path.resolve(pkgDir, 'tsconfig.json'),
]
if (types) {
args.push('--declaration')
}
return await execa('tsc', args, {
stdio: 'inherit',
})
}
await execa(
......@@ -79,7 +83,7 @@ async function build(target) {
'--environment',
[`NODE_ENV:${env}`, types ? `TYPES:true` : ``, `TARGET:${target}`]
.filter(Boolean)
.join(',')
.join(','),
],
{ stdio: 'inherit' }
)
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册