Skip to content

Commit c42ec34

Browse files
committed
update
1 parent 27b6be7 commit c42ec34

File tree

7 files changed

+69
-29
lines changed

7 files changed

+69
-29
lines changed

demo/LICENSE

-25
This file was deleted.

demo/app.vue

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<div>
33
<v-title title="Vue组件化"></v-title>
44
<v-button @click="handleClick">点击按钮</v-button>
5+
<p>
6+
<img src="./images/image.png" style="width: 200px;">
7+
</p>
58
</div>
69
</template>
710
<script>

demo/images/image.png

1.07 MB
Loading

demo/index.ejs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-CN">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Webpack App</title>
6+
<link rel="stylesheet" href="<%= htmlWebpackPlugin.files.css[0] %>">
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<script type="text/javascript" src="<%= htmlWebpackPlugin.files.js[0] %>"></script>
11+
</body>
12+
</html>

demo/package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"dev": "webpack-dev-server --open --config webpack.config.js"
8+
"dev": "webpack-dev-server --open --config webpack.config.js",
9+
"build": "webpack --progress --hide-modules --config webpack.prod.config.js"
910
},
1011
"author": "",
1112
"license": "ISC",
@@ -18,13 +19,17 @@
1819
"babel-runtime": "^6.23.0",
1920
"css-loader": "^0.27.3",
2021
"extract-text-webpack-plugin": "^2.1.0",
22+
"file-loader": "^0.10.1",
23+
"html-webpack-plugin": "^2.28.0",
2124
"style-loader": "^0.16.1",
25+
"url-loader": "^0.5.8",
2226
"vue-hot-reload-api": "^2.0.11",
2327
"vue-loader": "^11.3.4",
2428
"vue-style-loader": "^2.0.5",
2529
"vue-template-compiler": "^2.2.6",
2630
"webpack": "^2.3.2",
27-
"webpack-dev-server": "^2.4.2"
31+
"webpack-dev-server": "^2.4.2",
32+
"webpack-merge": "^4.1.0"
2833
},
2934
"dependencies": {
3035
"vue": "^2.2.6"

demo/webpack.config.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ var config = {
1818
options: {
1919
loaders: {
2020
css: ExtractTextPlugin.extract({
21-
use: 'css-loader',
22-
fallback: 'vue-style-loader'
21+
use: 'css-loader',
22+
fallback: 'vue-style-loader'
2323
})
2424
}
2525
}
@@ -35,6 +35,10 @@ var config = {
3535
use: 'css-loader',
3636
fallback: 'style-loader'
3737
})
38+
},
39+
{
40+
test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
41+
loader: 'url-loader?limit=1024'
3842
}
3943
]
4044
},

demo/webpack.prod.config.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var webpack = require('webpack');
2+
var HtmlWebpackPlugin = require('html-webpack-plugin');
3+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
4+
var merge = require('webpack-merge');
5+
var webpackBaseConfig = require('./webpack.config.js');
6+
7+
// 清空基本配置的插件列表
8+
webpackBaseConfig.plugins = [];
9+
10+
module.exports = merge(webpackBaseConfig, {
11+
output: {
12+
publicPath: '/dist/',
13+
// 将入口文件重命名为带有 20 位 hash 值的唯一文件
14+
filename: '[name].[hash].js'
15+
},
16+
plugins: [
17+
new ExtractTextPlugin({
18+
// 提取 css,并重命名为带有 20 位 hash 值的唯一文件
19+
filename: '[name].[hash].css',
20+
allChunks: true
21+
}),
22+
// 定义当前 node 环境为生产环境
23+
new webpack.DefinePlugin({
24+
'process.env': {
25+
NODE_ENV: '"production"'
26+
}
27+
}),
28+
// 压缩 js
29+
new webpack.optimize.UglifyJsPlugin({
30+
compress: {
31+
warnings: false
32+
}
33+
}),
34+
// 提取模板,并保存入口 html 文件
35+
new HtmlWebpackPlugin({
36+
filename: '../index_prod.html',
37+
template: './index.ejs',
38+
inject: false
39+
})
40+
]
41+
});

0 commit comments

Comments
 (0)