From f886ba6dd55457ab25d5086cf6e6f24b29627a5d Mon Sep 17 00:00:00 2001 From: dxd_sjtu Date: Tue, 9 Apr 2019 11:28:55 +0800 Subject: [PATCH] fix: compatible with assetHost and assetPath --- examples/simple/.manifest.json | 14 ++++++------- packages/beidou-view/app/extend/helper.js | 2 +- .../use-hash-asset-app/.manifest.json | 2 +- .../fixtures/with-hash-asset-path/foo.json | 2 +- packages/beidou-view/test/view.test.js | 21 +++++++------------ .../config/webpack/webpack.browser.js | 2 +- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/examples/simple/.manifest.json b/examples/simple/.manifest.json index e81c5292..82d2a794 100644 --- a/examples/simple/.manifest.json +++ b/examples/simple/.manifest.json @@ -1,9 +1,9 @@ { - "manifest.js": "/build/manifest_2b248f68.js", - "index.js": "/build/index_ec3f4aa7.js", - "script.js": "/build/script_5dba0438.js", - "script.css": "/build/script_93bb8fc6.css", - "static.js": "/build/static_0e65a2e0.js", - "style.js": "/build/style_bb8f1203.js", - "style.css": "/build/style_93bb8fc6.css" + "manifest.js": "manifest_6498f2ed.js", + "index.js": "index_48ebde7c.js", + "script.js": "script_3a4833fb.js", + "script.css": "script_93bb8fc6.css", + "static.js": "static_3f3fa875.js", + "style.js": "style_6d3bbe58.js", + "style.css": "style_93bb8fc6.css" } \ No newline at end of file diff --git a/packages/beidou-view/app/extend/helper.js b/packages/beidou-view/app/extend/helper.js index 2bf5f1dd..6bacb134 100644 --- a/packages/beidou-view/app/extend/helper.js +++ b/packages/beidou-view/app/extend/helper.js @@ -9,7 +9,7 @@ const helper = { */ [Symbol.for('beidou#asset')](filename, config) { if (this.app.config.view.useHashAsset && this.app.assetManifest[filename]) { - return this.app.assetManifest[filename]; + filename = this.app.assetManifest[filename]; } const assetHost = config.host || config.assetHost; const { assetPath } = config; diff --git a/packages/beidou-view/test/fixtures/use-hash-asset-app/.manifest.json b/packages/beidou-view/test/fixtures/use-hash-asset-app/.manifest.json index 4e0e333b..60e4f6c2 100644 --- a/packages/beidou-view/test/fixtures/use-hash-asset-app/.manifest.json +++ b/packages/beidou-view/test/fixtures/use-hash-asset-app/.manifest.json @@ -1,3 +1,3 @@ { - "index.js": "/build/index_ec3f4aa7.js" + "index.js": "index_ec3f4aa7.js" } \ No newline at end of file diff --git a/packages/beidou-view/test/fixtures/with-hash-asset-path/foo.json b/packages/beidou-view/test/fixtures/with-hash-asset-path/foo.json index 4e0e333b..60e4f6c2 100644 --- a/packages/beidou-view/test/fixtures/with-hash-asset-path/foo.json +++ b/packages/beidou-view/test/fixtures/with-hash-asset-path/foo.json @@ -1,3 +1,3 @@ { - "index.js": "/build/index_ec3f4aa7.js" + "index.js": "index_ec3f4aa7.js" } \ No newline at end of file diff --git a/packages/beidou-view/test/view.test.js b/packages/beidou-view/test/view.test.js index 546d3320..fd9f0736 100644 --- a/packages/beidou-view/test/view.test.js +++ b/packages/beidou-view/test/view.test.js @@ -156,28 +156,25 @@ describe('test/view.test.js', () => { app.close(); }); - it('should use asset with hash in local env', () => { + it('should use asset with hash in prod env', () => { const ctx = app.mockContext(); const asset = ctx.helper[Symbol.for('beidou#asset')].bind(ctx.helper); let url = asset('index.js', { assetPath: 'build', }); - assert(url === '/build/index_ec3f4aa7.js'); + assert(url === 'build/index_ec3f4aa7.js'); url = asset('index.js', { host: 'http://127.0.0.1', assetPath: 'build', }); - assert(url === '/build/index_ec3f4aa7.js'); + assert(url === 'http://127.0.0.1/build/index_ec3f4aa7.js'); url = asset('index.js', { host: '127.0.0.1', assetPath: 'build', }); - assert(url === '/build/index_ec3f4aa7.js'); - - url = asset('index.js'); - assert(url === '/build/index_ec3f4aa7.js'); + assert(url === 'http://127.0.0.1/build/index_ec3f4aa7.js'); }); }); @@ -196,28 +193,26 @@ describe('test/view.test.js', () => { app.close(); }); - it('should use asset with hash in local env', () => { + it('should use asset with hash in prod env', () => { const ctx = app.mockContext(); const asset = ctx.helper[Symbol.for('beidou#asset')].bind(ctx.helper); let url = asset('index.js', { assetPath: 'build', }); - assert(url === '/build/index_ec3f4aa7.js'); + assert(url === 'build/index_ec3f4aa7.js'); url = asset('index.js', { host: 'http://127.0.0.1', assetPath: 'build', }); - assert(url === '/build/index_ec3f4aa7.js'); + assert(url === 'http://127.0.0.1/build/index_ec3f4aa7.js'); url = asset('index.js', { host: '127.0.0.1', assetPath: 'build', }); - assert(url === '/build/index_ec3f4aa7.js'); + assert(url === 'http://127.0.0.1/build/index_ec3f4aa7.js'); - url = asset('index.js'); - assert(url === '/build/index_ec3f4aa7.js'); }); }); diff --git a/packages/beidou-webpack/config/webpack/webpack.browser.js b/packages/beidou-webpack/config/webpack/webpack.browser.js index 2f44ce31..38d185f6 100644 --- a/packages/beidou-webpack/config/webpack/webpack.browser.js +++ b/packages/beidou-webpack/config/webpack/webpack.browser.js @@ -96,7 +96,7 @@ module.exports = (app, entry, dev) => { if (viewConfig && viewConfig.useHashAsset && !dev) { factory.addPlugin( ManifestPlugin, - { fileName: viewConfig.hashAssetPath }, + { fileName: viewConfig.hashAssetPath, publicPath: '' }, 'WebpackManifestPlugin' ); factory.setPlugin(