Skip to content

Commit

Permalink
refactor: simplify webpack config (#40)
Browse files Browse the repository at this point in the history
* refactor: simplify webpack config

Signed-off-by: JayFate <[email protected]>

* refactor: rm dsl-xvm/src/loaders/module-loader.js

Signed-off-by: JayFate <[email protected]>

---------

Signed-off-by: JayFate <[email protected]>
  • Loading branch information
JayFate authored Jul 4, 2023
1 parent 0c2f926 commit 1b7ff3e
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 205 deletions.
4 changes: 4 additions & 0 deletions __tests__/examples/sample.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ const { Writable } = require('stream')
const fetch = require('node-fetch')
const fkill = require('fkill')
const stripAnsi = require('strip-ansi')
const fs = require('fs-extra')
const { run, lsfiles, readZip, wipeDynamic } = require('hap-dev-utils')
const { compile } = require('../../packages/hap-toolkit/lib')

const cwd = path.resolve(__dirname, '../../examples/sample')

describe('hap-toolkit', () => {
const distDir = path.resolve(cwd, 'dist')
fs.removeSync(distDir)

it(
'hap-build: 默认流式打包,包内存在META-INF文件',
async () => {
Expand Down
28 changes: 0 additions & 28 deletions packages/hap-dsl-xvm/src/loaders/module-loader.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/hap-packager/src/plugins/handler-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import Compilation from 'webpack/lib/Compilation'
import { compileOptionsMeta, compileOptionsObject } from '@hap-toolkit/shared-utils'
import { globalConfig } from '@hap-toolkit/shared-utils'
import { getEntryFiles } from '../common/info'

let ConcatSource
Expand Down Expand Up @@ -49,7 +49,7 @@ function wrapCode(fileName, compilation, enableE2e, entryFiles) {
}

if (entryFiles.indexOf(fileName) === -1) {
if (compileOptionsObject.splitChunksMode === compileOptionsMeta.splitChunksModeEnum.SMART) {
if (globalConfig.isSmartMode) {
// 抽取的JS chunk的处理,不加createPageHandler
return new ConcatSource(compilation.assets[fileName])
}
Expand Down
10 changes: 2 additions & 8 deletions packages/hap-packager/src/plugins/zip-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@

import fs from 'fs-extra'
import path from 'path'
import {
colorconsole,
readJson,
globalConfig,
compileOptionsMeta,
compileOptionsObject
} from '@hap-toolkit/shared-utils'
import { colorconsole, readJson, globalConfig, compileOptionsMeta } from '@hap-toolkit/shared-utils'
import { sortFilesBy, lsdirdeep, genPriorities } from '../common/utils'
import { getSkeletonConfig } from '../common/info'
import { DIGEST_ZIP_PATH } from '../common/constant'
Expand Down Expand Up @@ -322,7 +316,7 @@ ZipPlugin.prototype.apply = function (compiler) {
}

// 抽取公共JS:app-chunks.json放在app.js之前,page-chunks.json放在app.js之后,便于流式加载
if (compileOptionsObject.splitChunksMode === compileOptionsMeta.splitChunksModeEnum.SMART) {
if (globalConfig.isSmartMode) {
const appIndex = options.priorities.findIndex((item) => {
return item === 'app.js'
})
Expand Down
9 changes: 2 additions & 7 deletions packages/hap-packager/src/webpack.post.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@

import path from 'path'
import { sync as resolveSync } from 'resolve'
import {
globalConfig,
readJson,
compileOptionsMeta,
compileOptionsObject
} from '@hap-toolkit/shared-utils'
import { globalConfig, readJson, compileOptionsObject } from '@hap-toolkit/shared-utils'

import {
CopyDslPlugin,
Expand Down Expand Up @@ -116,7 +111,7 @@ function postHook(webpackConf, defaultsOptions, quickappConfig = {}) {
}

// 抽取公共js(仅smart模式开启)
if (compileOptionsObject.splitChunksMode === compileOptionsMeta.splitChunksModeEnum.SMART) {
if (globalConfig.isSmartMode) {
webpackConf.plugins.push(
new SplitChunksAdaptPlugin({
subpackages,
Expand Down
4 changes: 3 additions & 1 deletion packages/hap-shared-utils/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ export default {
outputPath: './build', // 输出目录,
dataCoverage: './.nyc_output', // 项目运行的代码覆盖率数据
command: 'build',
server: { port: 8000 }
server: { port: 8000 },
// 代码风格规则
isSmartMode: false
}

Large diffs are not rendered by default.

Loading

0 comments on commit 1b7ff3e

Please sign in to comment.