mirror of
https://github.com/jxnblk/mdx-deck.git
synced 2024-11-26 00:35:02 +03:00
build: add non-ssr-build
This commit is contained in:
parent
112233e7ef
commit
885883eec5
@ -8,6 +8,7 @@
|
||||
"scripts": {
|
||||
"start": "mdx-deck demo.mdx",
|
||||
"build": "mdx-deck build demo.mdx",
|
||||
"build-browser": "mdx-deck build-browser demo.mdx",
|
||||
"now-build": "yarn build"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -9,6 +9,7 @@
|
||||
"scripts": {
|
||||
"start": "yarn workspace @mdx-deck/docs start",
|
||||
"build": "yarn workspace @mdx-deck/docs build",
|
||||
"build:browser": "yarn workspace @mdx-deck/docs build-browser",
|
||||
"test": "jest"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -102,6 +102,19 @@ switch (cmd) {
|
||||
process.exit(1)
|
||||
})
|
||||
break
|
||||
case 'build-browser':
|
||||
log('building browser mode')
|
||||
const buildBrowser = require('./lib/build.browser')
|
||||
buildBrowser(opts)
|
||||
.then(res => {
|
||||
log('done')
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(err => {
|
||||
log.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
break
|
||||
case 'dev':
|
||||
default:
|
||||
log('starting dev server')
|
||||
|
37
packages/mdx-deck/lib/build.browser.js
Normal file
37
packages/mdx-deck/lib/build.browser.js
Normal file
@ -0,0 +1,37 @@
|
||||
const webpack = require('webpack')
|
||||
const createConfig = require('./config')
|
||||
|
||||
const buildBrowser = async (opts = {}) => {
|
||||
const config = createConfig(opts)
|
||||
|
||||
config.mode = 'production'
|
||||
config.output = {
|
||||
path: opts.outDir,
|
||||
filename: '[name].[contenthash:8].js',
|
||||
}
|
||||
config.optimization = {
|
||||
splitChunks: {
|
||||
chunks: 'all',
|
||||
},
|
||||
}
|
||||
|
||||
const compiler = webpack(config)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
compiler.run((err, stats) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
return
|
||||
}
|
||||
|
||||
if (stats.compilation.errors && stats.compilation.errors.length) {
|
||||
reject(stats.compilation.errors)
|
||||
return
|
||||
}
|
||||
|
||||
resolve(stats)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = buildBrowser
|
Loading…
Reference in New Issue
Block a user