Skip to content

Commit

Permalink
Add inferring of development options from webpack loader mode
Browse files Browse the repository at this point in the history
Closes GH-2198.
Closes GH-2201.

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
remcohaszing committed Dec 26, 2022
1 parent 5f68330 commit 600b12a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/loader/lib/index.js
Expand Up @@ -35,7 +35,10 @@ const cache = new WeakMap()
export function loader(value, callback) {
/** @type {Defaults} */
const defaults = this.sourceMap ? {SourceMapGenerator} : {}
const options = /** @type {CompileOptions} */ (this.getOptions())
const options = {
development: this.mode === 'development',
.../** @type {CompileOptions} */ (this.getOptions())
}
const config = {...defaults, ...options}
const hash = getOptionsHash(options)
// Some loaders set `undefined` (see `TypeStrong/ts-loader`).
Expand Down
16 changes: 15 additions & 1 deletion packages/loader/test/index.test.js
Expand Up @@ -95,6 +95,13 @@ webpack.mdx:1:22: Unexpected end of file in expression, expected a corresponding
'should compile (react)'
)

const reactOutput = await fs.readFile(new URL('react.cjs', base), 'utf8')
assert.not.match(
reactOutput,
/react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_\d+__\.jsxDEV/,
'should infer the development option from webpack’s production mode'
)

await fs.unlink(new URL('react.cjs', base))

// Preact and source maps
Expand Down Expand Up @@ -138,8 +145,15 @@ webpack.mdx:1:22: Unexpected end of file in expression, expected a corresponding
'should compile (preact)'
)

const preactOutput = await fs.readFile(new URL('preact.cjs', base), 'utf8')
assert.match(
preactOutput,
/preact_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_\d+__\.jsxDEV/,
'should infer the development option from webpack’s development mode'
)

assert.match(
String(await fs.readFile(new URL('preact.cjs', base))),
preactOutput,
/\/\/# sourceMappingURL/,
'should add a source map if requested'
)
Expand Down

1 comment on commit 600b12a

@vercel
Copy link

@vercel vercel bot commented on 600b12a Dec 26, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

mdx – ./

mdx-mdx.vercel.app
mdxjs.com
mdx-git-main-mdx.vercel.app
v2.mdxjs.com

Please sign in to comment.