Skip to content

Commit aef7021

Browse files
committed
optimize bundle removing vue from output
1 parent 822a1cd commit aef7021

File tree

8 files changed

+208
-133
lines changed

8 files changed

+208
-133
lines changed

build/config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import path from 'path';
22

33
const config = {
4-
projectRoot: path.resolve(__dirname, '../'),
5-
rootPath: path.resolve(__dirname, '../dist'),
6-
nodePath: path.resolve(__dirname, '../../node_modules'),
4+
projectRoot: path.join(__dirname, '../'),
5+
rootPath: path.join(__dirname, '../dist'),
6+
nodePath: path.join(__dirname, '../node_modules'),
7+
srcPath: 'src',
78
docsPath: 'docs',
89
indexPath: 'docs/index.html',
910
publicPath: '/',

build/webpack/debug-lib.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1+
import webpack from 'webpack';
12
import merge from 'webpack-merge';
23
import ExtractTextPlugin from 'extract-text-webpack-plugin';
4+
import OptimizeJsPlugin from 'optimize-js-plugin';
35
import prodConfig from './prod-lib';
46

57
const devConfig = merge(prodConfig, {
68
output: {
79
filename: '[name].debug.js'
810
},
9-
devtool: 'source-map',
10-
plugins: []
11+
devtool: 'source-map'
1112
});
1213

13-
devConfig.plugins.push(new ExtractTextPlugin('[name].css'));
14+
devConfig.plugins = [
15+
new webpack.optimize.OccurenceOrderPlugin(),
16+
new webpack.optimize.DedupePlugin(),
17+
new OptimizeJsPlugin({
18+
sourceMap: false
19+
}),
20+
new ExtractTextPlugin('[name].css')
21+
];
1422

1523
export default devConfig;

build/webpack/prod-docs.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import autoprefixer from 'autoprefixer';
55
import ExtractTextPlugin from 'extract-text-webpack-plugin';
66
import CopyWebpackPlugin from 'copy-webpack-plugin';
77
import HtmlWebpackPlugin from 'html-webpack-plugin';
8+
import OptimizeJsPlugin from 'optimize-js-plugin';
89
import config from '../config';
910
import baseConfig from './base';
1011

12+
const docsPath = path.join(config.rootPath, config.docsPath);
1113

1214
export default merge(baseConfig, {
1315
output: {
14-
path: path.join(config.rootPath, 'docs'),
16+
path: docsPath,
1517
publicPath: '',
1618
filename: '[name].[chunkhash:8].js',
1719
chunkFilename: '[name].[chunkhash:8].js'
@@ -28,28 +30,32 @@ export default merge(baseConfig, {
2830
]
2931
},
3032
plugins: [
33+
new webpack.optimize.DedupePlugin(),
3134
new webpack.optimize.UglifyJsPlugin({
3235
compress: {
3336
warnings: false
34-
}
37+
},
38+
comments: false
39+
}),
40+
new OptimizeJsPlugin({
41+
sourceMap: false
3542
}),
36-
new webpack.optimize.OccurenceOrderPlugin(),
3743
new ExtractTextPlugin('[name].[contenthash:8].css'),
3844
new CopyWebpackPlugin([
3945
{
4046
context: config.assetsPath,
4147
from: '**/*',
42-
to: path.join(config.rootPath, 'docs', 'assets')
48+
to: path.join(docsPath, 'assets')
4349
},
4450
{
4551
context: config.docsPath,
4652
from: 'changelog.html',
47-
to: path.join(config.rootPath, 'docs')
53+
to: docsPath
4854
},
4955
{
5056
context: config.docsPath,
5157
from: 'versions.json',
52-
to: path.join(config.rootPath, 'docs')
58+
to: docsPath
5359
}
5460
]),
5561
new HtmlWebpackPlugin({
@@ -77,15 +83,20 @@ export default merge(baseConfig, {
7783
}),
7884
new webpack.optimize.CommonsChunkPlugin({
7985
name: 'vendor',
80-
minChunks: (module) => {
86+
minChunks(module) {
8187
let resource = module.resource;
8288

83-
return resource && (/\.js$/).test(resource) && resource.indexOf(config.nodePath) === 0;
89+
if (resource && (/\.js$/).test(resource)) {
90+
return resource.indexOf(config.nodePath) >= 0;
91+
}
92+
93+
return false;
8494
}
8595
}),
8696
new webpack.optimize.CommonsChunkPlugin({
8797
name: 'manifest',
8898
chunks: ['vendor']
89-
})
99+
}),
100+
new webpack.optimize.OccurenceOrderPlugin()
90101
]
91102
});

build/webpack/prod-lib.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import webpack from 'webpack';
44
import merge from 'webpack-merge';
55
import autoprefixer from 'autoprefixer';
66
import ExtractTextPlugin from 'extract-text-webpack-plugin';
7+
import OptimizeJsPlugin from 'optimize-js-plugin';
78
import config from '../config';
89
import baseConfig from './base';
910

11+
const version = process.env.VERSION || require('../../package.json').version;
12+
1013
function getDirectories(src) {
1114
return fs.readdirSync(src).filter((file) => {
1215
return fs.statSync(path.join(src, file)).isDirectory();
@@ -43,13 +46,32 @@ export default merge(baseConfig, {
4346
})
4447
]
4548
},
49+
externals: {
50+
vue: 'Vue'
51+
},
4652
plugins: [
53+
new webpack.optimize.DedupePlugin(),
54+
new webpack.IgnorePlugin(/vue/),
4755
new webpack.optimize.UglifyJsPlugin({
4856
compress: {
4957
warnings: false
50-
}
58+
},
59+
comments: false
5160
}),
5261
new webpack.optimize.OccurenceOrderPlugin(),
62+
new OptimizeJsPlugin({
63+
sourceMap: false
64+
}),
65+
new webpack.BannerPlugin(
66+
`/*!
67+
* Vue Material v${version}
68+
* Made with love by Marcos Moura
69+
* Released under the MIT License.
70+
*/`
71+
, {
72+
raw: true,
73+
entryOnly: true
74+
}),
5375
new ExtractTextPlugin('[name].css')
5476
]
5577
});

docs/src/App.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,17 @@
321321
}
322322
}
323323
}
324+
325+
.phone-viewport {
326+
width: 360px;
327+
height: 540px;
328+
margin-right: 16px;
329+
display: inline-block;
330+
position: relative;
331+
overflow: hidden;
332+
background-color: #fff;
333+
border: 1px solid rgba(#000, .12);
334+
}
324335
</style>
325336

326337
<script>

docs/src/pages/components/List.vue

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -951,19 +951,6 @@
951951
</page-content>
952952
</template>
953953

954-
<style lang="scss">
955-
.phone-viewport {
956-
width: 360px;
957-
height: 540px;
958-
margin-right: 16px;
959-
display: inline-block;
960-
position: relative;
961-
overflow: hidden;
962-
background-color: #fff;
963-
border: 1px solid rgba(#000, .12);
964-
}
965-
</style>
966-
967954
<style lang="scss" scoped>
968955
.phone-viewport {
969956
height: 400px;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"html-webpack-plugin": "^2.24.1",
7474
"json-loader": "^0.5.4",
7575
"node-sass": "^4.1.1",
76+
"optimize-js-plugin": "^0.0.4",
7677
"ora": "^0.4.0",
7778
"raw-loader": "^0.5.1",
7879
"sass-loader": "^4.1.1",

0 commit comments

Comments
 (0)