Skip to content
This repository has been archived by the owner on Dec 3, 2018. It is now read-only.

Read bsconfig instead of webpack options #27

Merged
merged 6 commits into from
Sep 18, 2017

Conversation

arnarthor
Copy link
Collaborator

This changes the loader to read the bsconfig instead of having separate webpack options which need to stay in sync with bsconfig.json.

I developed this with this version of read-bsconfig so when that PR has been merged, I can bump the version of the dependency here and it should be a non breaking change then.

@arnarthor arnarthor requested a review from rrdelaney September 7, 2017 22:05
index.js Outdated
@@ -89,11 +90,29 @@ const getCompiledFileSync = (moduleDir, path) => {
return transformSrc(moduleDir, res.toString())
}

const getBsConfigModuleOptions = buildDir => {
Copy link
Owner

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

index.js Outdated
@@ -89,11 +90,29 @@ const getCompiledFileSync = (moduleDir, path) => {
return transformSrc(moduleDir, res.toString())
}

const getBsConfigModuleOptions = buildDir => {
const bsconfig = readBsConfigSync(buildDir)
Copy link
Owner

Choose a reason for hiding this comment

The 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

Copy link
Owner

Choose a reason for hiding this comment

The 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

index.js Outdated
throw new Error(`bsconfig not found in ${buildDir}`)
}

if (!bsconfig['package-specs'] || !bsconfig['package-specs'].length) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think package-specs needs to be defined, doesn't it default to using CommonJS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 'js' like we do in the options part 👍

index.js Outdated
const moduleDir = options.module || 'js'
const inSourceBuild = options.inSource || false
const bsconfig = getBsConfigModuleOptions(buildDir)
const moduleDir = bsconfig.module || 'js'
Copy link
Owner

Choose a reason for hiding this comment

The 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Owner

Choose a reason for hiding this comment

The 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 👍

Copy link
Owner

Choose a reason for hiding this comment

The 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

@rrdelaney
Copy link
Owner

read-bsconfig should work on Node LTS now after removing async/await

@rrdelaney rrdelaney merged commit b228152 into master Sep 18, 2017
@rrdelaney rrdelaney deleted the use-bsconfig-for-settings branch September 18, 2017 22:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants