Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(karma-webpack): handle outputPath correctly #360

Merged

Conversation

alabbas-ali
Copy link
Contributor

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

Refer to #357

The webpack output is not always the JS as first URL output

Copy link
Contributor

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

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

@alabbas-ali Thx for taking a stab at this again :)

@@ -17,6 +17,15 @@ var isBlocked = false

const normalize = (file) => file.replace(/\\/g, '/')

var getJsOutput = (outputPathArray) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

- var getJsOutput
+ var getOutputPath
- ... = (outputPathArray) =>
+  ... = (outputPath) =>

@@ -17,6 +17,15 @@ var isBlocked = false

const normalize = (file) => file.replace(/\\/g, '/')

var getJsOutput = (outputPathArray) => {
for (var _i = 0; _i < outputPathArray.length; _i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

- var _i
+ var i

@@ -17,6 +17,15 @@ var isBlocked = false

const normalize = (file) => file.replace(/\\/g, '/')

var getJsOutput = (outputPathArray) => {
for (var _i = 0; _i < outputPathArray.length; _i++) {
if (outputPathArray[_i].indexOf(".js") != -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How des this work? Could you give a five examples please? What happens if e.g file.js.map takes precedence?

Copy link
Contributor

Choose a reason for hiding this comment

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

- !=
+ !==

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How des this work? Could you give a five examples please? What happens if e.g file.js.map
takes precedence?

You are right. I did not consider this case actually? I have in my webpack config 3 entries. like
entry: {
app: ${scriptsPath}/ibe/${IBEClient}/app.ts,
vendor: ${scriptsPath}/vendor.browser.ts,
polyfills: ${scriptsPath}/polyfills.browser.ts,
}
So, I move the entries to Karma config to get the same output form webpack. and remove it form webpack config. mostly I didn't see this case because is the .js output is always before file.js.map output in all my cases. The problem I faced is if the webpack shanks has .css.map as first output.

In any case i will add .js.map to if condition which should solve this case also :)

this.outputs[entryPath] = outputPath
if (Array.isArray(outputPath))
outputPath = getJsOutput(outputPath)
if (outputPath != null)
Copy link
Contributor

Choose a reason for hiding this comment

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

- !=
+ !==

@michael-ciniawsky michael-ciniawsky changed the title 🐛 fix multiple output files, assumption fist file is JS is wrong fix(karma-webpack): handle outputPath correctly Sep 22, 2018
@michael-ciniawsky michael-ciniawsky added this to the 3.0.6 milestone Sep 22, 2018
@michael-ciniawsky
Copy link
Contributor

@alabbas-ali In which case(s) is the .js file not the first one in the list? Could you eleborate a bit here please?

@alabbas-ali
Copy link
Contributor Author

@alabbas-ali In which case(s) is the .js file not the first one in the list? Could you eleborate a bit here please?

As I said in the comment up. I have 3 entries:

entry: {
app: ${scriptsPath}/ibe/${IBEClient}/app.ts,
vendor: ${scriptsPath}/vendor.browser.ts,
polyfills: ${scriptsPath}/polyfills.browser.ts,
}

I move them to karma config, with devtool: 'inline-source-map' the output was the .js files as first output.
I had also .js.map and .css as output array for each chank.
But I also test it with devtool: 'source-map' which it was fine also a case.
Unfortunately, I had to at some point to change the order of the entire like:
entry: {
vendor: ${scriptsPath}/vendor.browser.ts,
polyfills: ${scriptsPath}/polyfills.browser.ts,
app: ${scriptsPath}/ibe/${IBEClient}/app.ts,
}
with devtool: 'source-map'
which made .css.map as first ouput for some reason.

@dominykas
Copy link

Using https://github.com/webpack-contrib/mini-css-extract-plugin also moves the CSS to be the first entry in the list.

@alabbas-ali
Copy link
Contributor Author

Are you going to merge this in the near future ??

@matthieu-foucault

This comment has been minimized.

@alabbas-ali
Copy link
Contributor Author

Could You merge this also ???

@matthieu-foucault matthieu-foucault merged commit 6d6a69a into codymikol:3.0.0 Nov 22, 2018
@dominykas
Copy link

Thanks for the merge! Anything left to do before this can be published on npm?

@matthieu-foucault
Copy link
Collaborator

It seems that the fix that we published in 4.0.0-rc.3 didn't fix things for everyone (see #355 ), so I'll investigate that before publishing

@alabbas-ali alabbas-ali deleted the fix-multiple-output-files branch November 23, 2018 17:26
@Lyrkan
Copy link

Lyrkan commented Mar 11, 2019

@matthieu-foucault Hi!

We recently noticed this issue in Webpack Encore (see symfony/webpack-encore#256 (comment)) since we always use the mini-css-extract-plugin.

Is there any plan about releasing a new 3.x version with that fix? (it seems to work fine with 4.0.0-rc.6)

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

Successfully merging this pull request may close these issues.

5 participants