Skip to content

Commit 600b12a

Browse files
authoredDec 26, 2022
Add inferring of development options from webpack loader mode
Closes GH-2198. Closes GH-2201. Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com> Reviewed-by: Titus Wormer <tituswormer@gmail.com>
1 parent 5f68330 commit 600b12a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
 

‎packages/loader/lib/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ const cache = new WeakMap()
3535
export function loader(value, callback) {
3636
/** @type {Defaults} */
3737
const defaults = this.sourceMap ? {SourceMapGenerator} : {}
38-
const options = /** @type {CompileOptions} */ (this.getOptions())
38+
const options = {
39+
development: this.mode === 'development',
40+
.../** @type {CompileOptions} */ (this.getOptions())
41+
}
3942
const config = {...defaults, ...options}
4043
const hash = getOptionsHash(options)
4144
// Some loaders set `undefined` (see `TypeStrong/ts-loader`).

‎packages/loader/test/index.test.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ webpack.mdx:1:22: Unexpected end of file in expression, expected a corresponding
9595
'should compile (react)'
9696
)
9797

98+
const reactOutput = await fs.readFile(new URL('react.cjs', base), 'utf8')
99+
assert.not.match(
100+
reactOutput,
101+
/react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_\d+__\.jsxDEV/,
102+
'should infer the development option from webpack’s production mode'
103+
)
104+
98105
await fs.unlink(new URL('react.cjs', base))
99106

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

148+
const preactOutput = await fs.readFile(new URL('preact.cjs', base), 'utf8')
149+
assert.match(
150+
preactOutput,
151+
/preact_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_\d+__\.jsxDEV/,
152+
'should infer the development option from webpack’s development mode'
153+
)
154+
141155
assert.match(
142-
String(await fs.readFile(new URL('preact.cjs', base))),
156+
preactOutput,
143157
/\/\/# sourceMappingURL/,
144158
'should add a source map if requested'
145159
)

1 commit comments

Comments
 (1)

vercel[bot] commented on Dec 26, 2022

@vercel[bot]

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.