Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.

Commit bc7672f

Browse files
committed
async fetch router resource
1 parent cb05501 commit bc7672f

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</head>
1111
<body>
1212
<div id="app"></div>
13-
<script src="/build/bundle.js"></script>
13+
<script src="/build/vendor.js"></script>
14+
<script src="/build/main.js"></script>
1415
</body>
1516
</html>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
"redux-thunk": "^2.1.0",
4949
"seamless-immutable": "^7.0.0",
5050
"uuid": "^3.0.0",
51-
"webpack": "^2.2.1",
52-
"webpack-dev-server": "^2.2.0-rc.0"
51+
"webpack": "^2.6.1",
52+
"webpack-dev-server": "^2.4.5"
5353
},
5454
"devDependencies": {
5555
"babel-core": "6.24.1",

webpack.config.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,22 @@ HashBundlePlugin.prototype.apply = (compiler) => {
2020
if (!stats.errors.length) {
2121
const htmlFileName = 'index.html';
2222
const html = fs.readFileSync(path.join(__dirname, htmlFileName), 'utf8');
23-
const htmlOutput = html.replace(/\/build\/.?bundle\.js/, `${'/build/'}${stats.hash}${'.bundle.js'}`);
23+
const htmlOutput = html.replace(/\/build\/.?main\.js/, `${'/build/'}${stats.hash}${'.main.js'}`);
24+
const vendorOutput = htmlOutput.replace(/\/build\/.?vendor\.js/, `${'/build/'}${stats.hash}${'.vendor.js'}`);
2425

25-
fs.writeFileSync(path.join(__dirname, htmlFileName), htmlOutput);
26+
fs.writeFileSync(path.join(__dirname, htmlFileName), vendorOutput);
27+
//fs.writeFileSync(path.join(__dirname, htmlFileName), vendorOutput);
2628
}
2729
});
2830
};
2931

3032
const config = {
3133
entry: ['babel-polyfill', path.resolve(__dirname, 'src')],
3234
output: {
33-
filename: `${isProd ? '[hash].' : ''}bundle.js`,
35+
filename: `${isProd ? '[hash].' : ''}[name].js`,
3436
path: path.resolve(__dirname, 'build'),
3537
publicPath: '/build/',
38+
chunkFilename: '[chunkhash:8].[name].chunk.js',
3639
},
3740
resolve: {
3841
extensions: ['.jsx', '.js', '.css', '.json', 'scss'],
@@ -65,6 +68,13 @@ const config = {
6568
}],
6669
},
6770
plugins: [
71+
new webpack.optimize.CommonsChunkPlugin({
72+
name: 'vendor',
73+
minChunks: function (module) {
74+
// 该配置假定你引入的 vendor 存在于 node_modules 目录中
75+
return module.context && module.context.indexOf('node_modules') !== -1;
76+
}
77+
}),
6878
new webpack.LoaderOptionsPlugin({
6979
options: {
7080
postcss: [

0 commit comments

Comments
 (0)