Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 新增--buildVersion,便于修改outputDir #3564

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,6 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


添加一行代码
6 changes: 4 additions & 2 deletions packages/taro-cli/bin/taro-build
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ program
.option('--plugin [typeName]', 'Build Taro plugin project, weapp')
.option('--port [port]', 'Specified port')
.option('--release', 'Release quickapp')
.option('--buildVersion [buildVersionName]', 'Build version, 1.0.0/2.0.0-bate.1')
.parse(process.argv)

const { type, watch, ui, port, release } = program
const { type, watch, ui, port, release, buildVersion } = program
let { env, plugin } = program

env = process.env.NODE_ENV || env
Expand Down Expand Up @@ -70,5 +71,6 @@ build(appPath, {
type,
watch,
port: typeof port === 'string' ? port: undefined,
release: !!release
release: !!release,
buildVersion: typeof buildVersion === 'string' ? buildVersion : undefined
})
6 changes: 3 additions & 3 deletions packages/taro-cli/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import CONFIG from './config'
import { BUILD_TYPES, PROJECT_CONFIG } from './util/constants'
import { IBuildConfig } from './util/types'

export default function build (appPath, buildConfig: IBuildConfig) {
const { type, watch, platform, port, release } = buildConfig
export default function build(appPath, buildConfig: IBuildConfig) {
const { type, watch, platform, port, release, buildVersion } = buildConfig
const configDir = require(path.join(appPath, PROJECT_CONFIG))(_.merge)
const outputPath = path.join(appPath, configDir.outputRoot || CONFIG.OUTPUT_DIR)
if (!fs.existsSync(outputPath)) {
Expand All @@ -19,7 +19,7 @@ export default function build (appPath, buildConfig: IBuildConfig) {
}
switch (type) {
case BUILD_TYPES.H5:
buildForH5(appPath, { watch, port })
buildForH5(appPath, { watch, port,buildVersion })
break
case BUILD_TYPES.WEAPP:
buildForWeapp(appPath, { watch })
Expand Down
5 changes: 4 additions & 1 deletion packages/taro-cli/src/h5/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class Compiler {
})
}

async buildDist ({ watch, port }: IBuildConfig) {
async buildDist({ watch, port, buildVersion }: IBuildConfig) {
const entryFileName = this.entryFileName
const projectConfig = this.projectConfig
const h5Config = this.h5Config
Expand Down Expand Up @@ -205,6 +205,9 @@ class Compiler {
port,
sourceRoot
})
if (watch == undefined && buildVersion) {
h5Config.outputRoot = buildVersion;
}

const webpackRunner = await npmProcess.getNpmPkg('@tarojs/webpack-runner', this.appPath)
webpackRunner(this.appPath, h5Config)
Expand Down
3 changes: 2 additions & 1 deletion packages/taro-cli/src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export interface IBuildConfig {
watch?: boolean,
platform?: string,
port?: number,
release?: boolean
release?: boolean,
buildVersion?: string
}

export interface IMiniAppBuildConfig {
Expand Down