@@ -11,10 +11,13 @@ const path = require('path')
11
11
12
12
const dir = path . resolve ( os . tmpdir ( ) )
13
13
14
- const babel = async (
15
- code ,
16
- { isServer = false , resourcePath = 'index.js' , development = false } = { }
17
- ) => {
14
+ const babel = async ( code , queryOpts = { } ) => {
15
+ const {
16
+ isServer = false ,
17
+ resourcePath = 'index.js' ,
18
+ development = false ,
19
+ } = queryOpts
20
+
18
21
let isAsync = false
19
22
return new Promise ( ( resolve , reject ) => {
20
23
function callback ( err , content ) {
@@ -47,7 +50,10 @@ const babel = async (
47
50
cwd : dir ,
48
51
isServer,
49
52
distDir : path . resolve ( dir , '.next' ) ,
50
- pagesDir : path . resolve ( dir , 'pages' ) ,
53
+ pagesDir :
54
+ 'pagesDir' in queryOpts
55
+ ? queryOpts . pagesDir
56
+ : path . resolve ( dir , 'pages' ) ,
51
57
cache : false ,
52
58
development,
53
59
hasReactRefresh : Boolean ( ! isServer && development ) ,
@@ -196,6 +202,28 @@ describe('next-babel-loader', () => {
196
202
expect ( code ) . toMatchInlineSnapshot ( `"if(false){}"` )
197
203
} )
198
204
205
+ it ( 'should handle no pagesDir' , async ( ) => {
206
+ const code = await babel (
207
+ `
208
+ import dynamic from 'next/dynamic'
209
+
210
+ const Comp = dynamic(() => import('comp'))
211
+
212
+ export default function Page(props) {
213
+ return <Comp />
214
+ }
215
+ ` ,
216
+ {
217
+ pagesDir : undefined ,
218
+ }
219
+ )
220
+ expect (
221
+ code . replace ( / m o d u l e s : \[ " .* ?" / , 'modules:["/path/to/page"' )
222
+ ) . toMatchInlineSnapshot (
223
+ `"import React from\\"react\\";var __jsx=React.createElement;import dynamic from'next/dynamic';var Comp=dynamic(function(){return import('comp');},{loadableGenerated:{webpack:function webpack(){return[require.resolveWeak('comp')];},modules:[\\"/path/to/page\\"+'comp']}});export default function Page(props){return __jsx(Comp,null);}"`
224
+ )
225
+ } )
226
+
199
227
it ( 'should not drop unused exports by default' , async ( ) => {
200
228
const code = await babel (
201
229
// effectful
0 commit comments