Skip to content

Commit 886c406

Browse files
authored
Merge pull request #47 from mpvue/develop
update: mpvue-loader 1.1.2
2 parents 2f1dd6f + c2e63c5 commit 886c406

File tree

9 files changed

+64
-68
lines changed

9 files changed

+64
-68
lines changed

template/build/webpack.base.conf.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ 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 relative = require('relative')
810

911
function resolve (dir) {
1012
return path.join(__dirname, '..', dir)
1113
}
1214

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-
}, {})
15+
function getEntry (rootSrc) {
16+
var map = {};
17+
glob.sync(rootSrc + '/pages/**/main.js')
18+
.forEach(file => {
19+
var key = relative(rootSrc, file).replace('.js', '');
20+
map[key] = file;
21+
})
22+
return map;
2123
}
2224

2325
const appEntry = { app: resolve('./src/main.js') }
@@ -108,6 +110,19 @@ module.exports = {
108110
]
109111
},
110112
plugins: [
111-
new MpvuePlugin()
113+
new MpvuePlugin(),
114+
new CopyWebpackPlugin([{
115+
from: '**/*.json',
116+
to: ''
117+
}], {
118+
context: 'src/'
119+
}),
120+
new CopyWebpackPlugin([
121+
{
122+
from: path.resolve(__dirname, '../static'),
123+
to: path.resolve(__dirname, '../dist/static'),
124+
ignore: ['.*']
125+
}
126+
])
112127
]
113128
}

template/build/webpack.dev.conf.js

Lines changed: 9 additions & 17 deletions
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('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')
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')
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('css/[name].[contenthash].css')
46-
filename: utils.assetsPath('css/[name].wxss')
45+
// filename: utils.assetsPath('[name].[contenthash].css')
46+
filename: utils.assetsPath('[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: 'vendor',
56+
name: 'common/vendor',
5757
minChunks: function (module, count) {
5858
// any required modules inside node_modules are extracted to vendor
5959
return (
@@ -64,17 +64,9 @@ module.exports = merge(baseWebpackConfig, {
6464
}
6565
}),
6666
new webpack.optimize.CommonsChunkPlugin({
67-
name: 'manifest',
68-
chunks: ['vendor']
67+
name: 'common/manifest',
68+
chunks: ['common/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-
]),
7870

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

template/build/webpack.prod.conf.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ var webpackConfig = merge(baseWebpackConfig, {
2424
devtool: config.build.productionSourceMap ? '#source-map' : false,
2525
output: {
2626
path: config.build.assetsRoot,
27-
// filename: utils.assetsPath('js/[name].[chunkhash].js'),
28-
// chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
29-
filename: utils.assetsPath('js/[name].js'),
30-
chunkFilename: utils.assetsPath('js/[id].js')
27+
// filename: utils.assetsPath('[name].[chunkhash].js'),
28+
// chunkFilename: utils.assetsPath('[id].[chunkhash].js')
29+
filename: utils.assetsPath('[name].js'),
30+
chunkFilename: utils.assetsPath('[id].js')
3131
},
3232
plugins: [
3333
// http://vuejs.github.io/vue-loader/en/workflow/production.html
@@ -39,8 +39,8 @@ var webpackConfig = merge(baseWebpackConfig, {
3939
}),
4040
// extract css into its own file
4141
new ExtractTextPlugin({
42-
// filename: utils.assetsPath('css/[name].[contenthash].css')
43-
filename: utils.assetsPath('css/[name].wxss')
42+
// filename: utils.assetsPath('[name].[contenthash].css')
43+
filename: utils.assetsPath('[name].wxss')
4444
}),
4545
// Compress extracted CSS. We are using this plugin so that possible
4646
// duplicated CSS from different components can be deduped.
@@ -72,7 +72,7 @@ var webpackConfig = merge(baseWebpackConfig, {
7272
new webpack.HashedModuleIdsPlugin(),
7373
// split vendor js into its own file
7474
new webpack.optimize.CommonsChunkPlugin({
75-
name: 'vendor',
75+
name: 'common/vendor',
7676
minChunks: function (module, count) {
7777
// any required modules inside node_modules are extracted to vendor
7878
return (
@@ -85,17 +85,9 @@ var webpackConfig = merge(baseWebpackConfig, {
8585
// extract webpack runtime and module manifest to its own file in order to
8686
// prevent vendor hash from being updated whenever app bundle is updated
8787
new webpack.optimize.CommonsChunkPlugin({
88-
name: 'manifest',
89-
chunks: ['vendor']
90-
}),
91-
// copy custom static assets
92-
new CopyWebpackPlugin([
93-
{
94-
from: path.resolve(__dirname, '../static'),
95-
to: config.build.assetsSubDirectory,
96-
ignore: ['.*']
97-
}
98-
])
88+
name: 'common/manifest',
89+
chunks: ['common/vendor']
90+
})
9991
]
10092
})
10193

template/config/index.js

Lines changed: 2 additions & 2 deletions
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: 'static',
9+
assetsSubDirectory: '',
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: 'static',
29+
assetsSubDirectory: '',
3030
assetsPublicPath: '/',
3131
proxyTable: {},
3232
// CSS Sourcemaps off by default because relative paths are "buggy"

template/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"vuex": "^3.0.1"{{/vuex}}
1919
},
2020
"devDependencies": {
21-
"mpvue-loader": "1.0.13",
21+
"mpvue-loader": "^1.1.2",
2222
"mpvue-webpack-target": "^1.0.0",
2323
"mpvue-template-compiler": "^1.0.11",
2424
"portfinder": "^1.0.13",
@@ -27,7 +27,8 @@
2727
"px2rpx-loader": "^0.1.10",
2828
"babel-core": "^6.22.1",
2929
"glob": "^7.1.2",
30-
"webpack-mpvue-asset-plugin": "0.0.2",
30+
"webpack-mpvue-asset-plugin": "^0.1.1",
31+
"relative": "^3.0.2",
3132
{{#lint}}
3233
"babel-eslint": "^8.2.3",
3334
{{/lint}}

template/src/app.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"pages": [
3+
"pages/index/main",
4+
"pages/counter/main",
5+
"pages/logs/main"
6+
],
7+
"window": {
8+
"backgroundTextStyle": "light",
9+
"navigationBarBackgroundColor": "#fff",
10+
"navigationBarTitleText": "WeChat",
11+
"navigationBarTextStyle": "black"
12+
}
13+
}

template/src/main.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,3 @@ App.mpType = 'app'{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
1010

1111
const app = new Vue(App){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
1212
app.$mount(){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
13-
14-
export default {
15-
// 这个字段走 app.json
16-
config: {
17-
// 页面前带有 ^ 符号的,会被编译成首页,其他页面可以选填,我们会自动把 webpack entry 里面的入口页面加进去
18-
pages: ['pages/logs/main', '^pages/index/main'],
19-
window: {
20-
backgroundTextStyle: 'light',
21-
navigationBarBackgroundColor: '#fff',
22-
navigationBarTitleText: 'WeChat',
23-
navigationBarTextStyle: 'black'{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
24-
}{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
25-
}{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
26-
}{{#if_eq lintConfig "airbnb"}};{{/if_eq}}

template/src/pages/logs/main.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,3 @@ import App from './index'{{#if_eq lintConfig "airbnb"}};{{/if_eq}}
33

44
const app = new Vue(App){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
55
app.$mount(){{#if_eq lintConfig "airbnb"}};{{/if_eq}}
6-
7-
export default {
8-
config: {
9-
navigationBarTitleText: '查看启动日志'{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
10-
}{{#if_eq lintConfig "airbnb"}},{{/if_eq}}
11-
}{{#if_eq lintConfig "airbnb"}};{{/if_eq}}

template/src/pages/logs/main.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"navigationBarTitleText": "查看启动日志"
3+
}

0 commit comments

Comments
 (0)