Skip to content

Commit

Permalink
feat(service): synchronous webpack.config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Nov 2, 2019
1 parent 857bf0c commit f8b1d46
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@nodepack/service/package.json
Expand Up @@ -42,6 +42,7 @@
"cli-highlight": "^2.1.1",
"cliui": "^5.0.0",
"cosmiconfig": "^5.2.1",
"deasync": "^0.1.15",
"dotenv": "^8.1.0",
"execa": "^2.0.4",
"find-up": "^4.1.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/@nodepack/service/src/lib/Service.js
Expand Up @@ -76,6 +76,9 @@ module.exports = class Service {

/** @type {string} */
this.configPath = null

// @ts-ignore
process.NODEPACK_SERVICE = this
}

resolvePlugins () {
Expand Down
25 changes: 25 additions & 0 deletions packages/@nodepack/service/weback.config.js
@@ -0,0 +1,25 @@
// this file is for cases where we need to access the
// webpack config as a file when using CLI commands.

const deasync = require('deasync')

async function resolve (cb) {
try {
/** @type {import('./src/lib/Service')} */
let service = process.NODEPACK_SERVICE

if (!service || process.env.NODEPACK_API_MODE) {
const Service = require('./src/lib/Service')
service = new Service(process.env.NODEPACK_CONTEXT || process.cwd())
await service.init(process.env.NODEPACK_ENV || process.env.NODE_ENV || 'development')
}

const config = await service.resolveWebpackConfig()
cb(null, config)
} catch (e) {
cb(e, null)
}
}

const resolveWebpackConfig = deasync(resolve)
module.exports = resolveWebpackConfig()

0 comments on commit f8b1d46

Please sign in to comment.