Skip to content

Commit

Permalink
fix: compatible with assetHost and assetPath
Browse files Browse the repository at this point in the history
  • Loading branch information
ahungrynoob committed Apr 9, 2019
1 parent 61c4b96 commit f886ba6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 24 deletions.
14 changes: 7 additions & 7 deletions examples/simple/.manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion packages/beidou-view/app/extend/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"index.js": "/build/index_ec3f4aa7.js"
"index.js": "index_ec3f4aa7.js"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"index.js": "/build/index_ec3f4aa7.js"
"index.js": "index_ec3f4aa7.js"
}
21 changes: 8 additions & 13 deletions packages/beidou-view/test/view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand All @@ -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');
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/beidou-webpack/config/webpack/webpack.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f886ba6

Please sign in to comment.