1
1
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:
Peng Xiao 2019-03-26 10:21:25 +08:00
parent 112233e7ef
commit 885883eec5
4 changed files with 52 additions and 0 deletions

View File

@ -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": {

View File

@ -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": {

View File

@ -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')

View 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