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

Add inferring of development options from webpack loader mode #2201

Merged
merged 2 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/loader/lib/index.js
Original file line number Diff line number Diff line change
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())
}
remcohaszing marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
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