Skip to content

feat(packages/sui-widget-embedder): debug code #1900

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 26 additions & 10 deletions packages/sui-widget-embedder/bin/sui-widget-embedder-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ program
.parse(process.argv)

const {clean, remoteCdn: remoteCdnOption} = program.opts()

const remoteCdn = remoteCdnOption || suiWidgetEmbedderConfig.remoteCdn

if (clean) {
console.log('Removing previous build...')
console.log('sui-widget-embedder - Removing previous build...')

rmSync(PUBLIC_PATH, {force: true, recursive: true})

console.log('sui-widget-embedder - Build removed')
}

const build = ({page, remoteCdn}) => {
Expand All @@ -52,15 +54,23 @@ const build = ({page, remoteCdn}) => {
remoteCdn,
globalConfig: suiWidgetEmbedderConfig
})

console.log('sui-widget-embedder -', {page, remoteCdn, suiWidgetEmbedderConfig})

return new Promise((resolve, reject) => {
compiler.run((error, stats) => {
if (error) return reject(error)
try {
compiler.run((error, stats) => {
if (error) return reject(error)

console.log(`Webpack stats: ${stats}`)

console.log(`Webpack stats: ${stats}`)
if (stats.hasErrors()) return reject(new Error('Webpack build failed'))

if (stats.hasErrors()) return reject(new Error('Webpack build failed'))
resolve()
})
resolve()
})
} catch (err) {
console.log(err)
}
})
}

Expand All @@ -83,10 +93,13 @@ const pageConfigs = () =>

const createDownloader = async () => {
const staticManifests = manifests()
console.log('sui-widget-embedder -', staticManifests)
const staticPageConfigs = pageConfigs()

console.log('sui-widget-embedder -', staticPageConfigs)
const input = resolve(__dirname, '..', 'downloader', 'index.js')
console.log('sui-widget-embedder input -', input)
const output = resolve(process.cwd(), 'public', FILE_DOWNLOADER)
console.log('sui-widget-embedder output -', output)

try {
const downloader = await readFile(input, 'utf-8')
Expand All @@ -106,7 +119,10 @@ const createDownloader = async () => {
}

const serialPromiseExecution = promises => promises.reduce((acc, func) => acc.then(() => func()), Promise.resolve([]))
const pages = pagesFor({path: PAGES_FOLDER})

console.log('sui-widget-embedder -', pages)

serialPromiseExecution(pagesFor({path: PAGES_FOLDER}).map(page => () => build({page, remoteCdn})))
serialPromiseExecution(pages.map(page => () => build({page, remoteCdn})))
.then(createDownloader)
.catch(showError)
5 changes: 4 additions & 1 deletion packages/sui-widget-embedder/compiler/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ module.exports = ({page, remoteCdn, globalConfig = {}}) => {
publicPath: remoteCdn ? `${remoteCdn}/${page}/` : prodConfig.output.publicPath,
chunkLoadingGlobal: `webpackJsonp-${page}`
},
plugins: pipe(removePlugin('HtmlWebpackPlugin'))(prodConfig.plugins)
plugins: pipe(removePlugin('HtmlWebpackPlugin'))(prodConfig.plugins),
cache: false
}

console.log('sui-widget-embedder -', webpackConfig)

return webpack(webpackConfig)
}
Loading