-
Notifications
You must be signed in to change notification settings - Fork 22
Read bsconfig instead of webpack options #27
Changes from 2 commits
96cd9dc
38ef36d
8cd9559
3e1e07d
528e000
a7c9f97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
const { readBsConfigSync } = require('read-bsconfig') | ||
const path = require('path') | ||
const { readFile, readFileSync } = require('fs') | ||
const { execFile, execFileSync } = require('child_process') | ||
|
@@ -89,11 +90,29 @@ const getCompiledFileSync = (moduleDir, path) => { | |
return transformSrc(moduleDir, res.toString()) | ||
} | ||
|
||
const getBsConfigModuleOptions = buildDir => { | ||
const bsconfig = readBsConfigSync(buildDir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be a good idea to cache the result of this function. It's not expected to change for the process of the build, and this is run once per file for every build There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. read-bsconfig will cache a bsconfig for us now so it doesn't read more than once |
||
if (!bsconfig) { | ||
throw new Error(`bsconfig not found in ${buildDir}`) | ||
} | ||
|
||
if (!bsconfig['package-specs'] || !bsconfig['package-specs'].length) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that's right. If it's not defined i'll default to |
||
throw new Error('package-specs not defined in bsconfig') | ||
} | ||
|
||
const moduleSpec = bsconfig['package-specs'][0] | ||
const module = typeof moduleSpec === 'string' ? moduleSpec : moduleSpec.module | ||
const inSource = | ||
typeof moduleSpec === 'string' ? false : moduleSpec['in-source'] | ||
return { module, inSource } | ||
} | ||
|
||
module.exports = function loader() { | ||
const options = getOptions(this) || {} | ||
const buildDir = options.cwd || CWD | ||
const moduleDir = options.module || 'js' | ||
const inSourceBuild = options.inSource || false | ||
const bsconfig = getBsConfigModuleOptions(buildDir) | ||
const moduleDir = bsconfig.module || 'js' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this isn't a breaking change, can we add the options passed in from the Webpack config as the first choice? Something like: const moduleDir = options.module || bsconfig.module || 'js'
const inSourceBuild = options.inSource || bsconfig.inSource || false There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well technically it's not breaking since the options would just be ignored and if your options and bsconfig don't match bs-loader won't work today right? But I agree having the options there explicitly first is a safer change 👍 I'll add that back There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it a breaking change to make peoples' breaking builds work 🤔 But yea, I think it's a safer option too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing about that though is that then the defaults from reason-scripts will stay in place so in-source builds for that wouldn't work. Unless a new version of reason-scripts with this change would just remove the webpack options as well 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I think we should push that up on the reason-scripts side |
||
const inSourceBuild = bsconfig.inSource || false | ||
|
||
this.addContextDependency(this.context) | ||
const callback = this.async() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ const baseConfig = { | |
use: { | ||
loader, | ||
options: { | ||
module: 'es6', | ||
cwd: __dirname | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be async instead of blocking? The loader is run for everyfile and this would be a lot of overhead