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

Webpack bundler #611

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/commands/app/build.js
Expand Up @@ -17,7 +17,7 @@ const BaseCommand = require('../../BaseCommand')
const { Flags } = require('@oclif/core')
const { runScript, writeConfig } = require('../../lib/app-helper')
const RuntimeLib = require('@adobe/aio-lib-runtime')
const { bundle } = require('@adobe/aio-lib-web')
const { bundle, bundlewp } = require('@adobe/aio-lib-web')
const fs = require('fs-extra')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:build', { provider: 'debug' })

Expand Down Expand Up @@ -53,6 +53,9 @@ class Build extends BaseCommand {
}

async buildOneExt (name, config, flags, spinner) {

const useWebpackFront = flags['feature-use-webpack-for-web-assets']

const onProgress = !flags.verbose
? info => {
spinner.text = info
Expand Down Expand Up @@ -109,16 +112,22 @@ class Build extends BaseCommand {
if (script) {
spinner.fail(chalk.green(`build-static skipped by hook '${name}'`))
} else {
const entries = config.web.src + '/**/*.html'
const bundleOptions = {
shouldDisableCache: true,
shouldContentHash: flags['content-hash'],
shouldOptimize: flags['web-optimize'],
logLevel: flags.verbose ? 'verbose' : 'warn'
}
const bundler = await bundle(entries, config.web.distProd, bundleOptions, onProgress)
await bundler.run()
spinner.succeed(chalk.green(`Building web assets for '${name}'`))
if (useWebpackFront) {
const entries = config.web.src + '/index.js'
await bundlewp(entries, config.web.distProd, bundleOptions, onProgress)
spinner.succeed(chalk.green(`Building web assets for '${name}'`))
} else {
const entries = config.web.src + '/**/*.html'
const bundler = await bundle(entries, config.web.distProd, bundleOptions, onProgress)
await bundler.run()
spinner.succeed(chalk.green(`Building web assets for '${name}'`))
}
}
} catch (err) {
spinner.fail(chalk.green(`Building web assets for '${name}'`))
Expand Down Expand Up @@ -160,6 +169,11 @@ Build.flags = {
default: true,
allowNo: true
}),
'feature-use-webpack-for-web-assets': Flags.boolean({
default: false,
description: '(experimental) Use webpack to bundle web assets',
dependsOn: ['web-assets']
}),
'force-build': Flags.boolean({
description: '[default: true] Force a build even if one already exists',
default: true,
Expand Down
5 changes: 5 additions & 0 deletions src/commands/app/run.js
Expand Up @@ -209,6 +209,11 @@ Run.flags = {
default: true,
allowNo: true
}),
'feature-use-webpack-for-web-assets': Flags.boolean({
default: false,
description: '(experimental) Use webpack to bundle web assets',
dependsOn: ['web-assets']
}),
actions: Flags.boolean({
description: '[default: true] Run actions, defaults to true, to skip actions use --no-actions',
default: true,
Expand Down