Skip to content

Commit 710c2a2

Browse files
committed
fixed
1 parent 7414608 commit 710c2a2

File tree

24 files changed

+421
-152
lines changed

24 files changed

+421
-152
lines changed

build/webpack.base.conf.js

+17-37
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,22 @@ var config = require('../config')
55
var vueLoaderConfig = require('./vue-loader.conf')
66
var MpvuePlugin = require('webpack-mpvue-asset-plugin')
77
var glob = require('glob')
8-
var CopyWebpackPlugin = require('copy-webpack-plugin')
9-
var configFilesArray = []
10-
var relative = require('relative')
118

12-
function resolve(dir) {
9+
function resolve (dir) {
1310
return path.join(__dirname, '..', dir)
1411
}
1512

16-
function getEntry(rootSrc) {
17-
var map = {};
18-
glob.sync(rootSrc + '/pages/**/main.js')
19-
.forEach(file => {
20-
var key = relative(rootSrc, file).replace('.js', '');
21-
map[key] = file;
22-
})
23-
glob.sync(rootSrc + '/pages/**/main.json')
24-
.forEach(file => {
25-
configFilesArray.push({
26-
from: file,
27-
to: relative(rootSrc, file)
28-
})
29-
})
30-
return map;
13+
function getEntry (rootSrc, pattern) {
14+
var files = glob.sync(path.resolve(rootSrc, pattern))
15+
return files.reduce((res, file) => {
16+
var info = path.parse(file)
17+
var key = info.dir.slice(rootSrc.length + 1) + '/' + info.name
18+
res[key] = path.resolve(file)
19+
return res
20+
}, {})
3121
}
3222

33-
const appEntry = {
34-
app: resolve('./src/main.js')
35-
}
36-
configFilesArray.push({
37-
from: resolve('./src/main.json'),
38-
to: 'app.json'
39-
})
23+
const appEntry = { app: resolve('./src/main.js') }
4024
const pagesEntry = getEntry(resolve('./src'), 'pages/**/main.js')
4125
const entry = Object.assign({}, appEntry, pagesEntry)
4226

@@ -49,8 +33,9 @@ module.exports = {
4933
output: {
5034
path: config.build.assetsRoot,
5135
filename: '[name].js',
52-
publicPath: process.env.NODE_ENV === 'production' ?
53-
config.build.assetsPublicPath : config.dev.assetsPublicPath
36+
publicPath: process.env.NODE_ENV === 'production'
37+
? config.build.assetsPublicPath
38+
: config.dev.assetsPublicPath
5439
},
5540
resolve: {
5641
extensions: ['.js', '.vue', '.json'],
@@ -63,7 +48,8 @@ module.exports = {
6348
mainFields: ['browser', 'module', 'main']
6449
},
6550
module: {
66-
rules: [{
51+
rules: [
52+
{
6753
test: /\.vue$/,
6854
loader: 'mpvue-loader',
6955
options: vueLoaderConfig
@@ -94,7 +80,7 @@ module.exports = {
9480
loader: 'url-loader',
9581
options: {
9682
limit: 10000,
97-
name: utils.assetsPath('media/[name].[ext]')
83+
name: utils.assetsPath('media/[name]].[ext]')
9884
}
9985
},
10086
{
@@ -108,12 +94,6 @@ module.exports = {
10894
]
10995
},
11096
plugins: [
111-
new MpvuePlugin(),
112-
new CopyWebpackPlugin(configFilesArray),
113-
new CopyWebpackPlugin([{
114-
from: path.resolve(__dirname, '../static'),
115-
to: path.resolve(__dirname, '../dist/static'),
116-
ignore: ['.*']
117-
}])
97+
new MpvuePlugin()
11898
]
11999
}

build/webpack.dev.conf.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ module.exports = merge(baseWebpackConfig, {
2929
devtool: '#source-map',
3030
output: {
3131
path: config.build.assetsRoot,
32-
// filename: utils.assetsPath('[name].[chunkhash].js'),
33-
// chunkFilename: utils.assetsPath('[id].[chunkhash].js')
34-
filename: utils.assetsPath('[name].js'),
35-
chunkFilename: utils.assetsPath('[id].js')
32+
// filename: utils.assetsPath('js/[name].[chunkhash].js'),
33+
// chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
34+
filename: utils.assetsPath('js/[name].js'),
35+
chunkFilename: utils.assetsPath('js/[id].js')
3636
},
3737
plugins: [
3838
new webpack.DefinePlugin({
@@ -42,8 +42,8 @@ module.exports = merge(baseWebpackConfig, {
4242
// copy from ./webpack.prod.conf.js
4343
// extract css into its own file
4444
new ExtractTextPlugin({
45-
// filename: utils.assetsPath('[name].[contenthash].css')
46-
filename: utils.assetsPath('[name].wxss')
45+
// filename: utils.assetsPath('css/[name].[contenthash].css')
46+
filename: utils.assetsPath('css/[name].wxss')
4747
}),
4848
// Compress extracted CSS. We are using this plugin so that possible
4949
// duplicated CSS from different components can be deduped.
@@ -53,7 +53,7 @@ module.exports = merge(baseWebpackConfig, {
5353
}
5454
}),
5555
new webpack.optimize.CommonsChunkPlugin({
56-
name: 'common/vendor',
56+
name: 'vendor',
5757
minChunks: function (module, count) {
5858
// any required modules inside node_modules are extracted to vendor
5959
return (
@@ -64,9 +64,17 @@ module.exports = merge(baseWebpackConfig, {
6464
}
6565
}),
6666
new webpack.optimize.CommonsChunkPlugin({
67-
name: 'common/manifest',
68-
chunks: ['common/vendor']
67+
name: 'manifest',
68+
chunks: ['vendor']
6969
}),
70+
// copy custom static assets
71+
new CopyWebpackPlugin([
72+
{
73+
from: path.resolve(__dirname, '../static'),
74+
to: config.build.assetsSubDirectory,
75+
ignore: ['.*']
76+
}
77+
]),
7078

7179
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
7280
// new webpack.HotModuleReplacementPlugin(),

build/webpack.prod.conf.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ var webpackConfig = merge(baseWebpackConfig, {
2222
devtool: config.build.productionSourceMap ? '#source-map' : false,
2323
output: {
2424
path: config.build.assetsRoot,
25-
// filename: utils.assetsPath('[name].[chunkhash].js'),
26-
// chunkFilename: utils.assetsPath('[id].[chunkhash].js')
27-
filename: utils.assetsPath('[name].js'),
28-
chunkFilename: utils.assetsPath('[id].js')
25+
// filename: utils.assetsPath('js/[name].[chunkhash].js'),
26+
// chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
27+
filename: utils.assetsPath('js/[name].js'),
28+
chunkFilename: utils.assetsPath('js/[id].js')
2929
},
3030
plugins: [
3131
// http://vuejs.github.io/vue-loader/en/workflow/production.html
@@ -37,8 +37,8 @@ var webpackConfig = merge(baseWebpackConfig, {
3737
}),
3838
// extract css into its own file
3939
new ExtractTextPlugin({
40-
// filename: utils.assetsPath('[name].[contenthash].css')
41-
filename: utils.assetsPath('[name].wxss')
40+
// filename: utils.assetsPath('css/[name].[contenthash].css')
41+
filename: utils.assetsPath('css/[name].wxss')
4242
}),
4343
// Compress extracted CSS. We are using this plugin so that possible
4444
// duplicated CSS from different components can be deduped.
@@ -68,7 +68,7 @@ var webpackConfig = merge(baseWebpackConfig, {
6868
new webpack.HashedModuleIdsPlugin(),
6969
// split vendor js into its own file
7070
new webpack.optimize.CommonsChunkPlugin({
71-
name: 'common/vendor',
71+
name: 'vendor',
7272
minChunks: function (module, count) {
7373
// any required modules inside node_modules are extracted to vendor
7474
return (
@@ -81,9 +81,17 @@ var webpackConfig = merge(baseWebpackConfig, {
8181
// extract webpack runtime and module manifest to its own file in order to
8282
// prevent vendor hash from being updated whenever app bundle is updated
8383
new webpack.optimize.CommonsChunkPlugin({
84-
name: 'common/manifest',
85-
chunks: ['common/vendor']
86-
})
84+
name: 'manifest',
85+
chunks: ['vendor']
86+
}),
87+
// copy custom static assets
88+
new CopyWebpackPlugin([
89+
{
90+
from: path.resolve(__dirname, '../static'),
91+
to: config.build.assetsSubDirectory,
92+
ignore: ['.*']
93+
}
94+
])
8795
]
8896
})
8997

config/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
env: require('./prod.env'),
77
index: path.resolve(__dirname, '../dist/index.html'),
88
assetsRoot: path.resolve(__dirname, '../dist'),
9-
assetsSubDirectory: '',
9+
assetsSubDirectory: 'static',
1010
assetsPublicPath: '/',
1111
productionSourceMap: false,
1212
// Gzip off by default as many popular static hosts such as
@@ -26,7 +26,7 @@ module.exports = {
2626
port: 8080,
2727
// 在小程序开发者工具中不需要自动打开浏览器
2828
autoOpenBrowser: false,
29-
assetsSubDirectory: '',
29+
assetsSubDirectory: 'static',
3030
assetsPublicPath: '/',
3131
proxyTable: {},
3232
// CSS Sourcemaps off by default because relative paths are "buggy"

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"glob": "^7.1.2",
3535
"html-webpack-plugin": "^3.2.0",
3636
"http-proxy-middleware": "^0.18.0",
37-
"mpvue-loader": "^1.1.1-rc.2",
37+
"mpvue-loader": "1.0.13",
3838
"mpvue-template-compiler": "^1.0.11",
3939
"mpvue-webpack-target": "^1.0.0",
4040
"node-sass": "^4.9.2",
@@ -57,7 +57,7 @@
5757
"webpack-bundle-analyzer": "^2.2.1",
5858
"webpack-dev-middleware-hard-disk": "^1.12.0",
5959
"webpack-merge": "^4.1.0",
60-
"webpack-mpvue-asset-plugin": "^0.1.0"
60+
"webpack-mpvue-asset-plugin": "0.0.2"
6161
},
6262
"engines": {
6363
"node": ">= 4.0.0",

src/main.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ export default {
1212
// 这个字段走 app.json
1313
config: {
1414
// 页面前带有 ^ 符号的,会被编译成首页,其他页面可以选填,我们会自动把 webpack entry 里面的入口页面加进去
15-
pages: ['pages/logs/main', '^pages/index/main', 'pages/goods/main'],
16-
window: {
17-
backgroundTextStyle: 'light',
18-
navigationBarBackgroundColor: '#fff',
19-
navigationBarTitleText: '网易严选',
20-
navigationBarTextStyle: 'black'
15+
"pages": ["^pages/category/main", "pages/categorylist/main", "pages/topic/main", "pages/goods/main", "pages/index/main", "pages/logs/main"],
16+
"window": {
17+
"backgroundTextStyle": "light",
18+
"navigationBarBackgroundColor": "#fff",
19+
"navigationBarTitleText": "网易严选",
20+
"navigationBarTextStyle": "black"
2121
},
22-
tabBar: {
22+
"tabBar": {
2323
"backgroundColor": "#fafafa",
2424
"borderStyle": "white",
2525
"selectedColor": "#b4282d",
2626
"color": "#666",
2727
"list": [{
28-
"pagePath": "pages/index/main",
28+
"pagePath": "pages/goods/main",
2929
"iconPath": "static/images/ic_menu_choice_nor.png",
3030
"selectedIconPath": "static/images/ic_menu_choice_pressed.png",
3131
"text": "首页"
@@ -37,19 +37,19 @@ export default {
3737
"text": "专题"
3838
},
3939
{
40-
"pagePath": "pages/index/main",
40+
"pagePath": "pages/category/main",
4141
"iconPath": "static/images/ic_menu_sort_nor.png",
4242
"selectedIconPath": "static/images/ic_menu_sort_pressed.png",
4343
"text": "分类"
4444
},
4545
{
46-
"pagePath": "pages/index/main",
46+
"pagePath": "pages/topic/main",
4747
"iconPath": "static/images/ic_menu_shoping_nor.png",
4848
"selectedIconPath": "static/images/ic_menu_shoping_pressed.png",
4949
"text": "购物车"
5050
},
5151
{
52-
"pagePath": "pages/index/main",
52+
"pagePath": "pages/topic/main",
5353
"iconPath": "static/images/ic_menu_me_nor.png",
5454
"selectedIconPath": "static/images/ic_menu_me_pressed.png",
5555
"text": "我的"

src/main.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"pages": ["pages/category/main", "pages/topic/main", "pages/goods/main", "pages/index/main", "pages/logs/main"],
2+
"pages": ["pages/category/main", "pages/categorylist/main", "pages/topic/main", "pages/goods/main", "pages/index/main", "pages/logs/main"],
33
"window": {
44
"backgroundTextStyle": "light",
55
"navigationBarBackgroundColor": "#fff",
@@ -36,7 +36,7 @@
3636
"text": "购物车"
3737
},
3838
{
39-
"pagePath": "pages/index/main",
39+
"pagePath": "pages/topic/main",
4040
"iconPath": "static/images/ic_menu_me_nor.png",
4141
"selectedIconPath": "static/images/ic_menu_me_pressed.png",
4242
"text": "我的"

src/pages/branddetail/main.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Vue from 'vue'
2+
import App from './index'
3+
4+
const app = new Vue(App)
5+
app.$mount()
6+
export default {
7+
config: {},
8+
}

src/pages/brandlist/main.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Vue from 'vue'
2+
import App from './index'
3+
4+
const app = new Vue(App)
5+
app.$mount()
6+
export default {
7+
config: {},
8+
}

src/pages/cart/index.vue

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<template>
2+
<div>
3+
111
4+
<!-- <template> -->
5+
<div>
6+
<wxParse :content="artical" />
7+
</div>
8+
<!-- </template> -->
9+
</div>
10+
</template>
11+
12+
<script>
13+
import wxParse from "mpvue-wxparse";
14+
export default {
15+
created() {},
16+
data() {
17+
return {
18+
artical: "<div>何玉硕</div>"
19+
};
20+
},
21+
components: {
22+
wxParse
23+
},
24+
methods: {},
25+
computed: {}
26+
};
27+
</script>
28+
<style lang='scss' scoped>
29+
@import url("~mpvue-wxparse/src/wxParse.css");
30+
@import "./style";
31+
</style>

src/pages/cart/main.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Vue from 'vue'
2+
import App from './index'
3+
4+
const app = new Vue(App)
5+
app.$mount()
6+
export default {
7+
config: {},
8+
}

0 commit comments

Comments
 (0)