Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

fix(index): Add check for this.options #189

Closed
wants to merge 3 commits into from

Conversation

jquense
Copy link

@jquense jquense commented Aug 11, 2017

this.options doesn't seem to be defined always. If I don't have the LoaderOptionsPlugin it crashes :/

`this.options` doesn't seem to be defined always. If I don't have the LoaderOptionsPlugin it crashes :/
@jsf-clabot
Copy link

jsf-clabot commented Aug 11, 2017

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

src/index.js Outdated
@@ -10,7 +10,7 @@ export default function fileLoader(content) {

const query = loaderUtils.getOptions(this) || {};
const configKey = query.config || 'fileLoader';
const options = this.options[configKey] || {};
const options = this.options && this.options[configKey] || {};
Copy link
Member

Choose a reason for hiding this comment

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

Why? please provide more information, also need tests, thanks!

Copy link
Author

@jquense jquense Aug 12, 2017

Choose a reason for hiding this comment

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

I'm not sure what I would write a test for, without setting up and running through webpack. The loader assumes this.options is provided by webpack unconditionally, its not. It only exists in v2+ if the user provides the LoaderOptionsPlugin, a plugin that exists only to help ease migration from v1. This is just simple mistake on the webpack api I believe. Either this or add to the Readme saying the LoaderOptionsPlugin is required

Copy link
Member

Choose a reason for hiding this comment

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

@jquense i am use file-loader without LoaderOptionsPlugin, can your provide repo where it is not works?

Copy link
Author

Choose a reason for hiding this comment

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

Sure.

@codecov
Copy link

codecov bot commented Aug 12, 2017

Codecov Report

Merging #189 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #189      +/-   ##
=========================================
+ Coverage   97.43%   97.5%   +0.06%     
=========================================
  Files           2       2              
  Lines          39      40       +1     
  Branches       18      19       +1     
=========================================
+ Hits           38      39       +1     
  Misses          1       1
Impacted Files Coverage Δ
src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7e2998c...f8828f3. Read the comment docs.

@jquense
Copy link
Author

jquense commented Aug 12, 2017

Sorry about that, the problem is that if you do provide a LoadersOptionsPlugin but leave options undefined. On the face of it it seems like a tiny edge case. but we generally use functions to build our configs so this is actually easy to do e.g.

getLoaderOptions = (options) => new webpack.LoaderOptionsPlugins({
  minimize: true, 
  options
})

plugins: [getLoaderOptions()]

*.sublime-workspace
Copy link
Member

Choose a reason for hiding this comment

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

Please exclude this from commit, we use webpack-defaults for all repos, need do PR there https://github.com/webpack-contrib/webpack-defaults

Copy link
Author

Choose a reason for hiding this comment

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

Sorry I'm not sure what you want excluded here, the line was already there my editor just inserted a newline character. I'm not even using sublime

@michael-ciniawsky
Copy link
Member

@jquense In case you are using webpack >= v2.0.0 please setup options in module.rules instead, since LoaderOptionsPlugin main purpose was to support incompatible loaders with webpack >= v2.0.0 during webpackv2.0.0-betaand as migration path. It is not needed anymore for most loaders (e.gfile-loader). this.options` (Mutliple Configs) is going away hopefully soon (#184) since usage is deprecated

@michael-ciniawsky michael-ciniawsky changed the title Add check for this.options fix(index): Add check for this.options Aug 12, 2017
@alexander-akait
Copy link
Member

@michael-ciniawsky can we close this PR?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants