commit
00a421d728
|
@ -112,7 +112,7 @@ export function parseJs(
|
||||||
imports,
|
imports,
|
||||||
{ IS_MPA, currentPage, IS_ENTRY, DEPLOY_PATH, LEGACY_MODE } = {},
|
{ IS_MPA, currentPage, IS_ENTRY, DEPLOY_PATH, LEGACY_MODE } = {},
|
||||||
filename,
|
filename,
|
||||||
linePatch = 0
|
linePatch = 1
|
||||||
) {
|
) {
|
||||||
let fixedStyle = ''
|
let fixedStyle = ''
|
||||||
let ASSETS_DIR = '/@/'
|
let ASSETS_DIR = '/@/'
|
||||||
|
|
|
@ -18,6 +18,7 @@ export async function compileFiles(
|
||||||
options,
|
options,
|
||||||
{ verbose, imports, dist } = {}
|
{ verbose, imports, dist } = {}
|
||||||
) {
|
) {
|
||||||
|
let pageDir = options.IS_MPA && currentPage ? `pages/${currentPage}` : ''
|
||||||
options.currentPage = currentPage
|
options.currentPage = currentPage
|
||||||
|
|
||||||
for (let [path, it] of files) {
|
for (let [path, it] of files) {
|
||||||
|
@ -40,8 +41,6 @@ export async function compileFiles(
|
||||||
|
|
||||||
verbose && console.log(' 解析 %s ...', it.name)
|
verbose && console.log(' 解析 %s ...', it.name)
|
||||||
|
|
||||||
let pageDir = options.IS_MPA && currentPage ? `pages/${currentPage}` : ''
|
|
||||||
|
|
||||||
switch (it.ext) {
|
switch (it.ext) {
|
||||||
case '.vue':
|
case '.vue':
|
||||||
{
|
{
|
||||||
|
|
22
lib/dev.js
22
lib/dev.js
|
@ -166,13 +166,18 @@ export default async function createServer(root = '', conf = {}) {
|
||||||
let entry = fs.cat(page.entry)?.toString()
|
let entry = fs.cat(page.entry)?.toString()
|
||||||
let html = fs.cat(join(process.cwd(), 'index.html')).toString()
|
let html = fs.cat(join(process.cwd(), 'index.html')).toString()
|
||||||
|
|
||||||
entry = parseJs(entry, conf.imports, {
|
entry = parseJs(
|
||||||
|
entry,
|
||||||
|
conf.imports,
|
||||||
|
{
|
||||||
IS_MPA,
|
IS_MPA,
|
||||||
currentPage,
|
currentPage,
|
||||||
IS_ENTRY: true,
|
IS_ENTRY: true,
|
||||||
DEPLOY_PATH,
|
DEPLOY_PATH,
|
||||||
LEGACY_MODE
|
LEGACY_MODE
|
||||||
})
|
},
|
||||||
|
page.entry
|
||||||
|
)
|
||||||
|
|
||||||
code = parseHtml(html, {
|
code = parseHtml(html, {
|
||||||
page,
|
page,
|
||||||
|
@ -198,7 +203,6 @@ export default async function createServer(root = '', conf = {}) {
|
||||||
file = join(SOURCE_DIR, rpath)
|
file = join(SOURCE_DIR, rpath)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ndex.html
|
|
||||||
file = join(SOURCE_DIR, rpath)
|
file = join(SOURCE_DIR, rpath)
|
||||||
}
|
}
|
||||||
if (!fs.isfile(file)) {
|
if (!fs.isfile(file)) {
|
||||||
|
@ -267,19 +271,25 @@ export default async function createServer(root = '', conf = {}) {
|
||||||
if (fs.isfile(file)) {
|
if (fs.isfile(file)) {
|
||||||
code = fs.cat(file)
|
code = fs.cat(file)
|
||||||
} else if (fs.isfile(join(PUBLIC_DIR, rpath))) {
|
} else if (fs.isfile(join(PUBLIC_DIR, rpath))) {
|
||||||
code = fs.cat(join(PUBLIC_DIR, rpath))
|
file = join(PUBLIC_DIR, rpath)
|
||||||
|
code = fs.cat(file)
|
||||||
} else {
|
} else {
|
||||||
friendlyErrors(rpath, ext)
|
friendlyErrors(rpath, ext)
|
||||||
res.writeHead(404, USE_HTTPS ? void 0 : 'Not Found')
|
res.writeHead(404, USE_HTTPS ? void 0 : 'Not Found')
|
||||||
res.end('')
|
res.end('')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
code = parseJs(code + '', conf.imports, {
|
code = parseJs(
|
||||||
|
code + '',
|
||||||
|
conf.imports,
|
||||||
|
{
|
||||||
IS_MPA,
|
IS_MPA,
|
||||||
currentPage,
|
currentPage,
|
||||||
DEPLOY_PATH,
|
DEPLOY_PATH,
|
||||||
LEGACY_MODE
|
LEGACY_MODE
|
||||||
})
|
},
|
||||||
|
file
|
||||||
|
)
|
||||||
res.setHeader('content-type', MIME_TYPES.js)
|
res.setHeader('content-type', MIME_TYPES.js)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
42
lib/prod.js
42
lib/prod.js
|
@ -74,22 +74,6 @@ export default function compile(root = '', dist = '', conf = {}, verbose) {
|
||||||
: isCustomElement || defaultCustomElement
|
: isCustomElement || defaultCustomElement
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建线程池
|
|
||||||
if (THREADS_NUM > 0) {
|
|
||||||
for (let i = 0; i < THREADS_NUM; i++) {
|
|
||||||
WORKER_POOL.add(
|
|
||||||
new Worker(join(__dirname, './thread.js'), {
|
|
||||||
workerData: {
|
|
||||||
options,
|
|
||||||
verbose,
|
|
||||||
dist,
|
|
||||||
imports: conf.imports
|
|
||||||
}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.ls(SOURCE_DIR, true).forEach(path => {
|
fs.ls(SOURCE_DIR, true).forEach(path => {
|
||||||
if (fs.isdir(path)) {
|
if (fs.isdir(path)) {
|
||||||
return
|
return
|
||||||
|
@ -108,14 +92,29 @@ export default function compile(root = '', dist = '', conf = {}, verbose) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it.path === conf.inject.scss) {
|
if (path === conf.inject.scss) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
list.set(path, it)
|
list.set(path, it)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 创建线程池
|
||||||
|
if (THREADS_NUM > 0 && (IS_MPA || list.size > THREADS_NUM * 10)) {
|
||||||
|
for (let i = 0; i < THREADS_NUM; i++) {
|
||||||
|
WORKER_POOL.add(
|
||||||
|
new Worker(join(__dirname, './thread.js'), {
|
||||||
|
workerData: {
|
||||||
|
options,
|
||||||
|
verbose,
|
||||||
|
dist,
|
||||||
|
imports: conf.imports
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 优先处理静态目录, 之后的源码目录中, 以便如果有产生相同的文件名, 则覆盖静态目录中的文件
|
// 优先处理静态目录, 之后的源码目录中, 以便如果有产生相同的文件名, 则覆盖静态目录中的文件
|
||||||
if (fs.isdir(PUBLIC_DIR)) {
|
if (fs.isdir(PUBLIC_DIR)) {
|
||||||
console.log('\n正在处理静态资源 ...')
|
console.log('\n正在处理静态资源 ...')
|
||||||
|
@ -152,6 +151,7 @@ export default function compile(root = '', dist = '', conf = {}, verbose) {
|
||||||
list.delete(path)
|
list.delete(path)
|
||||||
files.set(path, { name, ext })
|
files.set(path, { name, ext })
|
||||||
})
|
})
|
||||||
|
|
||||||
if (THREADS_NUM > 0) {
|
if (THREADS_NUM > 0) {
|
||||||
chunk.set(currentPage, { page, files })
|
chunk.set(currentPage, { page, files })
|
||||||
JOBS_QUEUE.push(chunk)
|
JOBS_QUEUE.push(chunk)
|
||||||
|
@ -187,11 +187,10 @@ export default function compile(root = '', dist = '', conf = {}, verbose) {
|
||||||
let currentPage = PAGES_KEYS[0]
|
let currentPage = PAGES_KEYS[0]
|
||||||
let page = conf.pages[currentPage]
|
let page = conf.pages[currentPage]
|
||||||
|
|
||||||
list = [...list]
|
|
||||||
|
|
||||||
console.log(`正在生成 ${currentPage}.html ...`)
|
console.log(`正在生成 ${currentPage}.html ...`)
|
||||||
|
|
||||||
if (THREADS_NUM > 0) {
|
if (THREADS_NUM > 0 && list.size > THREADS_NUM * 10) {
|
||||||
|
list = [...list]
|
||||||
for (let i = 0; i < THREADS_NUM; i++) {
|
for (let i = 0; i < THREADS_NUM; i++) {
|
||||||
let start = i * chunkSize
|
let start = i * chunkSize
|
||||||
let end = start + chunkSize
|
let end = start + chunkSize
|
||||||
|
@ -203,6 +202,7 @@ export default function compile(root = '', dist = '', conf = {}, verbose) {
|
||||||
doJob()
|
doJob()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
options.isCustomElement = isCustomElement || defaultCustomElement
|
||||||
compileFiles(currentPage, page, list, options, {
|
compileFiles(currentPage, page, list, options, {
|
||||||
verbose,
|
verbose,
|
||||||
dist,
|
dist,
|
||||||
|
|
Loading…
Reference in New Issue