Skip to content

Commit 39a781d

Browse files
authored
Merge pull request #39 from mpvue/wz/feat-subcontracting
Wz/feat subcontracting
2 parents ac1b4fd + f7c1d57 commit 39a781d

File tree

6 files changed

+57
-60
lines changed

6 files changed

+57
-60
lines changed

template/build/webpack.base.conf.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,35 @@ 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 = []
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 = file.replace(rootSrc + '/', '').replace('.js', '');
20+
map[key] = file;
21+
})
22+
glob.sync(rootSrc + '/pages/**/main.json')
23+
.forEach(file => {
24+
configFilesArray.push({
25+
from: file,
26+
to: file.replace(rootSrc + '/', '')
27+
})
28+
})
29+
return map;
2130
}
2231

2332
const appEntry = { app: resolve('./src/main.js') }
33+
configFilesArray.push({
34+
from: resolve('./src/main.json'),
35+
to: 'app.json'
36+
})
2437
const pagesEntry = getEntry(resolve('./src'), 'pages/**/main.js')
2538
const entry = Object.assign({}, appEntry, pagesEntry)
2639

@@ -108,6 +121,7 @@ module.exports = {
108121
]
109122
},
110123
plugins: [
111-
new MpvuePlugin()
124+
new MpvuePlugin(),
125+
new CopyWebpackPlugin(configFilesArray)
112126
]
113127
}

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/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/main.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+
}

0 commit comments

Comments
 (0)