-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enable contenthash for assets #161
Changes from 3 commits
89c5618
55bf27c
7bc36e8
836f32a
8ec8d8d
18660ab
a7a90b8
d0efb91
d065a1e
61c4b96
f886ba6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"manifest.js": "/build/manifest_2b248f68.js", | ||
"index.js": "/build/index_ec3f4aa7.js", | ||
"script.js": "/build/script_f2970f26.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" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ module.exports = (appInfo) => { | |
placeHolder: '<!--$render$-->', | ||
}, | ||
view: { | ||
useHashAsset: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上 |
||
defaultViewEngine: 'react', | ||
defaultExtension: isTs ? '.tsx' : '.jsx', | ||
root: `${path.join(appInfo.baseDir, 'app/views')},${path.join( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
const { getAssetManifest } = require('./lib/utils'); | ||
|
||
module.exports = (app) => { | ||
// get asset with hash from cwd/manifes.json; | ||
if (app.config.view.useHashAsset) { | ||
if (app.config.env === 'local') { | ||
app.coreLogger.warn( | ||
'Detect view.useHashAsset in local env, will ignore it.' | ||
); | ||
app.config.view.useHashAsset = false; | ||
return; | ||
} | ||
app.assetManifest = getAssetManifest(app.baseDir); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 获取mapping资源文件最好可配置 |
||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import assert from 'assert'; | ||
|
||
const testStr = 'base view test'; | ||
|
||
/** | ||
* Text component | ||
* | ||
* @export | ||
* @class View | ||
* @extends {React.Component} | ||
*/ | ||
export default class View { | ||
static async getInitialProps() { | ||
return { | ||
title: 'beidou', | ||
}; | ||
} | ||
static async getStore() { | ||
return { | ||
getState: () => ({ testStr }), | ||
}; | ||
} | ||
|
||
static async getPartial(props) { | ||
assert(props.state === '{"testStr":"base view test"}'); | ||
return { partial: '', list: ['a', 'b', 'c'], store: 'store' }; | ||
} | ||
|
||
render({ partial, list, store, title }) { | ||
// See view.test.js BaseView.prototype.renderElement | ||
const partialResult = 'fake renderElement'; | ||
assert(partial === partialResult); | ||
|
||
assert(list.length === 3); | ||
for (const item of list) { | ||
assert(item === partialResult); | ||
} | ||
|
||
assert(store === partialResult); | ||
|
||
assert(title === 'beidou'); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
|
||
module.exports = _ => ({ | ||
view: { | ||
useHashAsset: true, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"index.js": "/build/index_ec3f4aa7.js" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "beidou-test-view-use-hash-asset-app" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,10 @@ | |
process.traceDeprecation = true; | ||
|
||
const webpack = require('webpack'); | ||
const path = require('path'); | ||
const TerserPlugin = require('terser-webpack-plugin'); | ||
const common = require('./webpack.common'); | ||
const { common, reservedKey } = require('./webpack.common'); | ||
const ManifestPlugin = require('webpack-manifest-plugin'); | ||
const { | ||
imageLoaderConfig, | ||
fileLoaderConfig, | ||
|
@@ -18,6 +20,7 @@ module.exports = (app, entry, dev) => { | |
const { pkg } = app.config; | ||
const factory = app.webpackFactory; | ||
const typescript = pkg && pkg.config && pkg.config.typescript; | ||
const reservedConfig = app.config.webpack[reservedKey]; | ||
common(app, entry, dev); | ||
[ | ||
{ | ||
|
@@ -62,7 +65,6 @@ module.exports = (app, entry, dev) => { | |
if (!dev) { | ||
factory.set('mode', 'production'); | ||
factory.addPlugin('DefinePlugin'); | ||
|
||
factory.set('optimization', { | ||
minimizer: [ | ||
new TerserPlugin({ | ||
|
@@ -92,5 +94,17 @@ module.exports = (app, entry, dev) => { | |
'HotModuleReplacementPlugin' | ||
); | ||
} | ||
if (reservedConfig.assetWithHash && !dev) { | ||
factory.addPlugin(ManifestPlugin, | ||
{ fileName: path.join(app.baseDir, 'manifest.json') }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mapping资源路径最好可配置资源路径。 |
||
'WebpackManifestPlugin' | ||
); | ||
factory | ||
.setPlugin( | ||
ExtractTextPlugin, | ||
'[name]_[md5:contenthash:hex:8].css', | ||
'ExtractTextPlugin' | ||
); | ||
} | ||
return factory.getConfig(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个配置是在beidou-view的插件下用的,最好放在beidou-view的配置下