Skip to content

Commit 6570492

Browse files
author
chouchouji
committed
fix: don't handle publicPath when it is set to auto
1 parent b87cabc commit 6570492

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

src/hooks.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ const emitHook = function emit(
8686
publicPath: true
8787
});
8888

89-
const publicPath = options.publicPath !== null ? options.publicPath : stats.publicPath;
89+
const publicPath =
90+
options.publicPath !== null
91+
? options.publicPath
92+
: stats.publicPath !== 'auto'
93+
? stats.publicPath
94+
: '';
9095
const { basePath, removeKeyHash } = options;
9196

9297
emitCountMap.set(manifestFileName, emitCount);

test/unit/paths.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,69 @@ test('should output unix paths', async (t) => {
220220
'some/dir/main.js': 'some/dir/main.js'
221221
});
222222
});
223+
224+
test('should handle publicPath set to auto', async (t) => {
225+
const config = {
226+
context: __dirname,
227+
entry: {
228+
one: '../fixtures/file.js'
229+
},
230+
output: {
231+
filename: `[name].${hashLiteral}.js`,
232+
path: join(outputPath, 'public-auto'),
233+
publicPath: 'auto'
234+
}
235+
};
236+
const { manifest, stats } = await compile(config, t);
237+
238+
// When publicPath is 'auto', it should not be added to the asset paths
239+
// The manifest should contain relative paths without any publicPath prefix
240+
t.deepEqual(manifest, {
241+
'one.js': `one.${stats.hash}.js`
242+
});
243+
});
244+
245+
test('should handle publicPath set to auto with basePath', async (t) => {
246+
const config = {
247+
context: __dirname,
248+
entry: {
249+
one: '../fixtures/file.js'
250+
},
251+
output: {
252+
filename: `[name].${hashLiteral}.js`,
253+
path: join(outputPath, 'public-auto-base'),
254+
publicPath: 'auto'
255+
}
256+
};
257+
const { manifest, stats } = await compile(config, t, {
258+
basePath: '/app/'
259+
});
260+
261+
// When publicPath is 'auto' but basePath is set, basePath should still work
262+
// but publicPath should not be added to the asset paths
263+
t.deepEqual(manifest, {
264+
'/app/one.js': `one.${stats.hash}.js`
265+
});
266+
});
267+
268+
test('should override auto publicPath when plugin publicPath is explicitly set', async (t) => {
269+
const config = {
270+
context: __dirname,
271+
entry: {
272+
one: '../fixtures/file.js'
273+
},
274+
output: {
275+
filename: `[name].${hashLiteral}.js`,
276+
path: join(outputPath, 'public-auto-override'),
277+
publicPath: 'auto'
278+
}
279+
};
280+
const { manifest, stats } = await compile(config, t, {
281+
publicPath: '/custom/'
282+
});
283+
284+
// When plugin publicPath is explicitly set, it should override the webpack auto setting
285+
t.deepEqual(manifest, {
286+
'one.js': `/custom/one.${stats.hash}.js`
287+
});
288+
});

0 commit comments

Comments
 (0)