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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webpack): allow function entries for `build.transpile` #6120

Merged
merged 8 commits into from Aug 3, 2019
Merged

Conversation

@Atinux
Copy link
Member

Atinux commented Jul 24, 2019

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

It's mostly a feature for module, thinking of @nuxt/http for example that need to add ky in build.transpile but only for legacy mode.

Before:

{
  build: {
    transpile: ['ky']
  }
}

After:

{
  build: {
    transpile: [
      ({ isModern }) => isModern ? null : 'ky'
    ]
  }
}

The main issue I see is that module author will have to check Nuxt version to be able to push a function in build.transpile otherwise it justs breaks 馃槩

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: nuxt/docs#1472)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.
@Atinux Atinux requested review from clarkdo, pi0 and nuxt/core-team Jul 24, 2019
@pi0 pi0 changed the title feat: handle build.transpile item to be a function feat(webpack): allow function entries for `build.transpile` Jul 24, 2019
@pi0

This comment has been minimized.

Copy link
Member

pi0 commented Jul 24, 2019

The main issue I see is that module author will have to check Nuxt version to be able to push a function in build.transpile otherwise it justs breaks cry

This is a feat/fix by next release. Nothing will be breaking.


Some other enhancements we could do is adding an option like transpileLegacy or allow object form like { name: 'ky', legacy: true } or { name: 'ky', modern: false }

@Atinux Atinux dismissed stale reviews from galvez and pi0 via 89d9876 Jul 24, 2019
@Atinux Atinux mentioned this pull request Jul 24, 2019
@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Jul 24, 2019

Codecov Report

Merging #6120 into dev will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev    #6120      +/-   ##
==========================================
+ Coverage   95.75%   95.75%   +<.01%     
==========================================
  Files          80       80              
  Lines        2659     2665       +6     
  Branches      682      686       +4     
==========================================
+ Hits         2546     2552       +6     
  Misses         97       97              
  Partials       16       16
Flag Coverage 螖
#e2e 100% <酶> (酶) 猬嗭笍
#fixtures 50.91% <75%> (+0.03%) 猬嗭笍
#unit 92.45% <100%> (+0.01%) 猬嗭笍
Impacted Files Coverage 螖
packages/webpack/src/config/base.js 94.89% <100%> (+0.16%) 猬嗭笍
packages/webpack/src/config/server.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 edf5e66...63dbd61. Read the comment docs.

Atinux added 2 commits Jul 24, 2019
Copy link
Member

clarkdo left a comment

If function is one of array items, then it can only return string or regex pattern.

Do you think is there any use case for multiple functions, maybe modules ?

How about just making transpile as function, like:

transpile: () => {
  return [
    'vue-test',
    '@vue/test'
  ]
}
if (pattern instanceof RegExp) {
items.push(pattern)
} else {
} else if (pattern) {

This comment has been minimized.

Copy link
@clarkdo

clarkdo Jul 24, 2019

Member

Should this be string ?

This comment has been minimized.

Copy link
@Atinux

Atinux Jul 29, 2019

Author Member

Yes, Will update to check typeof pattern === 'string'

@Atinux

This comment has been minimized.

Copy link
Member Author

Atinux commented Jul 29, 2019

@clarkdo Making build.transpile a function will be harder for modules author to extend it I guess, this is why I thought about handling a push as a method (see nuxt/http@2ce08de#diff-d1234a869b3d648ebfcdce5a76747d71R100)

Atinux added 2 commits Jul 29, 2019
@Atinux

This comment has been minimized.

Copy link
Member Author

Atinux commented Jul 29, 2019

Ready to review

@Atinux Atinux requested review from pi0, galvez and clarkdo Jul 29, 2019
@@ -20,10 +20,13 @@ export default class WebpackServerConfig extends WebpackBaseConfig {
const whitelist = [
/\.(?!js(x|on)?$)/i
]
for (const pattern of this.buildContext.buildOptions.transpile) {
for (let pattern of this.buildContext.buildOptions.transpile) {

This comment has been minimized.

Copy link
@manniL

manniL Jul 30, 2019

Member

Looks like we have a duplicate code block here (as in src/config/base.js, L61-70). Could we extract it somehow?

This comment has been minimized.

Copy link
@clarkdo

clarkdo Aug 3, 2019

Member

I will do it in another pr since this has been a long time

@clarkdo
clarkdo approved these changes Aug 3, 2019
@clarkdo clarkdo merged commit e8f1532 into dev Aug 3, 2019
9 checks passed
9 checks passed
Semantic Pull Request ready to be squashed
Details
[ci.azure] nuxt.js #20190729.3 succeeded
Details
ci/circleci: audit Your tests passed on CircleCI!
Details
ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: lint-app Your tests passed on CircleCI!
Details
ci/circleci: setup Your tests passed on CircleCI!
Details
ci/circleci: test-e2e Your tests passed on CircleCI!
Details
ci/circleci: test-unit Your tests passed on CircleCI!
Details
@clarkdo clarkdo deleted the fix/transpile-if branch Aug 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can鈥檛 perform that action at this time.