Skip to content

Commit 264abc5

Browse files
committed
cleanup
1 parent 17212c2 commit 264abc5

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/interpolateName.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function interpolateName(
2828
let resourcePath = loaderResourcePath
2929

3030
if (parsed.ext) {
31-
ext = parsed.ext.substr(1)
31+
ext = parsed.ext.slice(1)
3232
}
3333

3434
if (parsed.dir) {
@@ -41,7 +41,7 @@ export default function interpolateName(
4141
.relative(context, resourcePath + '_')
4242
.replace(/\\/g, '/')
4343
.replace(/\.\.(\/)?/g, '_$1')
44-
directory = directory.substr(0, directory.length - 1)
44+
directory = directory.slice(0, directory.length - 1)
4545
} else {
4646
directory = resourcePath.replace(/\\/g, '/').replace(/\.\.(\/)?/g, '_$1')
4747
}
@@ -59,7 +59,7 @@ export default function interpolateName(
5959
const hashIdx = query.indexOf('#')
6060

6161
if (hashIdx >= 0) {
62-
query = query.substr(0, hashIdx)
62+
query = query.slice(0, hashIdx)
6363
}
6464
}
6565

src/utils.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,9 @@ const getOutputAndPublicPath: GetOutputAndPublicPath = (
154154
if (configPublicPath) {
155155
if (typeof configPublicPath === 'function') {
156156
publicPath = configPublicPath(fileName)
157-
} else if (configPublicPath.endsWith('/')) {
158-
publicPath = configPublicPath + fileName
159157
} else {
160-
publicPath = `${configPublicPath}/${fileName}`
158+
publicPath = path.posix.join(configPublicPath, fileName)
161159
}
162-
163160
publicPath = JSON.stringify(publicPath)
164161
}
165162

test/utils.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { getOutputAndPublicPath } from '../lib/utils'
2+
3+
describe('Utils package', () => {
4+
it('should create both paths', () => {
5+
const { outputPath, publicPath } = getOutputAndPublicPath('file.png', {
6+
outputPath: '/dist/img/',
7+
publicPath: '/img',
8+
})
9+
expect(outputPath).toBe('/dist/img/file.png')
10+
expect(publicPath).toBe('"/img/file.png"')
11+
})
12+
})

0 commit comments

Comments
 (0)