diff --git a/template/build/webpack.base.conf.js b/template/build/webpack.base.conf.js index 9a2591c..a564a80 100644 --- a/template/build/webpack.base.conf.js +++ b/template/build/webpack.base.conf.js @@ -5,19 +5,21 @@ var config = require('../config') var vueLoaderConfig = require('./vue-loader.conf') var MpvuePlugin = require('webpack-mpvue-asset-plugin') var glob = require('glob') +var CopyWebpackPlugin = require('copy-webpack-plugin') +var relative = require('relative') function resolve (dir) { return path.join(__dirname, '..', dir) } -function getEntry (rootSrc, pattern) { - var files = glob.sync(path.resolve(rootSrc, pattern)) - return files.reduce((res, file) => { - var info = path.parse(file) - var key = info.dir.slice(rootSrc.length + 1) + '/' + info.name - res[key] = path.resolve(file) - return res - }, {}) +function getEntry (rootSrc) { + var map = {}; + glob.sync(rootSrc + '/pages/**/main.js') + .forEach(file => { + var key = relative(rootSrc, file).replace('.js', ''); + map[key] = file; + }) + return map; } const appEntry = { app: resolve('./src/main.js') } @@ -108,6 +110,19 @@ module.exports = { ] }, plugins: [ - new MpvuePlugin() + new MpvuePlugin(), + new CopyWebpackPlugin([{ + from: '**/*.json', + to: '' + }], { + context: 'src/' + }), + new CopyWebpackPlugin([ + { + from: path.resolve(__dirname, '../static'), + to: path.resolve(__dirname, '../dist/static'), + ignore: ['.*'] + } + ]) ] } diff --git a/template/build/webpack.dev.conf.js b/template/build/webpack.dev.conf.js index 9fb3ebb..af13377 100644 --- a/template/build/webpack.dev.conf.js +++ b/template/build/webpack.dev.conf.js @@ -29,10 +29,10 @@ module.exports = merge(baseWebpackConfig, { devtool: '#source-map', output: { path: config.build.assetsRoot, - // filename: utils.assetsPath('js/[name].[chunkhash].js'), - // chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') - filename: utils.assetsPath('js/[name].js'), - chunkFilename: utils.assetsPath('js/[id].js') + // filename: utils.assetsPath('[name].[chunkhash].js'), + // chunkFilename: utils.assetsPath('[id].[chunkhash].js') + filename: utils.assetsPath('[name].js'), + chunkFilename: utils.assetsPath('[id].js') }, plugins: [ new webpack.DefinePlugin({ @@ -42,8 +42,8 @@ module.exports = merge(baseWebpackConfig, { // copy from ./webpack.prod.conf.js // extract css into its own file new ExtractTextPlugin({ - // filename: utils.assetsPath('css/[name].[contenthash].css') - filename: utils.assetsPath('css/[name].wxss') + // filename: utils.assetsPath('[name].[contenthash].css') + filename: utils.assetsPath('[name].wxss') }), // Compress extracted CSS. We are using this plugin so that possible // duplicated CSS from different components can be deduped. @@ -53,7 +53,7 @@ module.exports = merge(baseWebpackConfig, { } }), new webpack.optimize.CommonsChunkPlugin({ - name: 'vendor', + name: 'common/vendor', minChunks: function (module, count) { // any required modules inside node_modules are extracted to vendor return ( @@ -64,17 +64,9 @@ module.exports = merge(baseWebpackConfig, { } }), new webpack.optimize.CommonsChunkPlugin({ - name: 'manifest', - chunks: ['vendor'] + name: 'common/manifest', + chunks: ['common/vendor'] }), - // copy custom static assets - new CopyWebpackPlugin([ - { - from: path.resolve(__dirname, '../static'), - to: config.build.assetsSubDirectory, - ignore: ['.*'] - } - ]), // https://github.com/glenjamin/webpack-hot-middleware#installation--usage // new webpack.HotModuleReplacementPlugin(), diff --git a/template/build/webpack.prod.conf.js b/template/build/webpack.prod.conf.js index f7df71d..14c5c72 100644 --- a/template/build/webpack.prod.conf.js +++ b/template/build/webpack.prod.conf.js @@ -24,10 +24,10 @@ var webpackConfig = merge(baseWebpackConfig, { devtool: config.build.productionSourceMap ? '#source-map' : false, output: { path: config.build.assetsRoot, - // filename: utils.assetsPath('js/[name].[chunkhash].js'), - // chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') - filename: utils.assetsPath('js/[name].js'), - chunkFilename: utils.assetsPath('js/[id].js') + // filename: utils.assetsPath('[name].[chunkhash].js'), + // chunkFilename: utils.assetsPath('[id].[chunkhash].js') + filename: utils.assetsPath('[name].js'), + chunkFilename: utils.assetsPath('[id].js') }, plugins: [ // http://vuejs.github.io/vue-loader/en/workflow/production.html @@ -39,8 +39,8 @@ var webpackConfig = merge(baseWebpackConfig, { }), // extract css into its own file new ExtractTextPlugin({ - // filename: utils.assetsPath('css/[name].[contenthash].css') - filename: utils.assetsPath('css/[name].wxss') + // filename: utils.assetsPath('[name].[contenthash].css') + filename: utils.assetsPath('[name].wxss') }), // Compress extracted CSS. We are using this plugin so that possible // duplicated CSS from different components can be deduped. @@ -72,7 +72,7 @@ var webpackConfig = merge(baseWebpackConfig, { new webpack.HashedModuleIdsPlugin(), // split vendor js into its own file new webpack.optimize.CommonsChunkPlugin({ - name: 'vendor', + name: 'common/vendor', minChunks: function (module, count) { // any required modules inside node_modules are extracted to vendor return ( @@ -85,17 +85,9 @@ var webpackConfig = merge(baseWebpackConfig, { // extract webpack runtime and module manifest to its own file in order to // prevent vendor hash from being updated whenever app bundle is updated new webpack.optimize.CommonsChunkPlugin({ - name: 'manifest', - chunks: ['vendor'] - }), - // copy custom static assets - new CopyWebpackPlugin([ - { - from: path.resolve(__dirname, '../static'), - to: config.build.assetsSubDirectory, - ignore: ['.*'] - } - ]) + name: 'common/manifest', + chunks: ['common/vendor'] + }) ] }) diff --git a/template/config/index.js b/template/config/index.js index d288fc2..5678f57 100644 --- a/template/config/index.js +++ b/template/config/index.js @@ -6,7 +6,7 @@ module.exports = { env: require('./prod.env'), index: path.resolve(__dirname, '../dist/index.html'), assetsRoot: path.resolve(__dirname, '../dist'), - assetsSubDirectory: 'static', + assetsSubDirectory: '', assetsPublicPath: '/', productionSourceMap: false, // Gzip off by default as many popular static hosts such as @@ -26,7 +26,7 @@ module.exports = { port: 8080, // 在小程序开发者工具中不需要自动打开浏览器 autoOpenBrowser: false, - assetsSubDirectory: 'static', + assetsSubDirectory: '', assetsPublicPath: '/', proxyTable: {}, // CSS Sourcemaps off by default because relative paths are "buggy" diff --git a/template/package.json b/template/package.json index 7b64659..8594c58 100644 --- a/template/package.json +++ b/template/package.json @@ -18,7 +18,7 @@ "vuex": "^3.0.1"{{/vuex}} }, "devDependencies": { - "mpvue-loader": "1.0.13", + "mpvue-loader": "^1.1.2", "mpvue-webpack-target": "^1.0.0", "mpvue-template-compiler": "^1.0.11", "portfinder": "^1.0.13", @@ -27,7 +27,8 @@ "px2rpx-loader": "^0.1.10", "babel-core": "^6.22.1", "glob": "^7.1.2", - "webpack-mpvue-asset-plugin": "0.0.2", + "webpack-mpvue-asset-plugin": "^0.1.1", + "relative": "^3.0.2", {{#lint}} "babel-eslint": "^8.2.3", {{/lint}} diff --git a/template/src/app.json b/template/src/app.json new file mode 100644 index 0000000..26a40e4 --- /dev/null +++ b/template/src/app.json @@ -0,0 +1,13 @@ +{ + "pages": [ + "pages/index/main", + "pages/counter/main", + "pages/logs/main" + ], + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "WeChat", + "navigationBarTextStyle": "black" + } +} diff --git a/template/src/main.js b/template/src/main.js index 2479283..4f7d478 100644 --- a/template/src/main.js +++ b/template/src/main.js @@ -10,17 +10,3 @@ App.mpType = 'app'{{#if_eq lintConfig "airbnb"}};{{/if_eq}} const app = new Vue(App){{#if_eq lintConfig "airbnb"}};{{/if_eq}} app.$mount(){{#if_eq lintConfig "airbnb"}};{{/if_eq}} - -export default { - // 这个字段走 app.json - config: { - // 页面前带有 ^ 符号的,会被编译成首页,其他页面可以选填,我们会自动把 webpack entry 里面的入口页面加进去 - pages: ['pages/logs/main', '^pages/index/main'], - window: { - backgroundTextStyle: 'light', - navigationBarBackgroundColor: '#fff', - navigationBarTitleText: 'WeChat', - navigationBarTextStyle: 'black'{{#if_eq lintConfig "airbnb"}},{{/if_eq}} - }{{#if_eq lintConfig "airbnb"}},{{/if_eq}} - }{{#if_eq lintConfig "airbnb"}},{{/if_eq}} -}{{#if_eq lintConfig "airbnb"}};{{/if_eq}} diff --git a/template/src/pages/logs/main.js b/template/src/pages/logs/main.js index 4752ddb..7a6645a 100644 --- a/template/src/pages/logs/main.js +++ b/template/src/pages/logs/main.js @@ -3,9 +3,3 @@ import App from './index'{{#if_eq lintConfig "airbnb"}};{{/if_eq}} const app = new Vue(App){{#if_eq lintConfig "airbnb"}};{{/if_eq}} app.$mount(){{#if_eq lintConfig "airbnb"}};{{/if_eq}} - -export default { - config: { - navigationBarTitleText: '查看启动日志'{{#if_eq lintConfig "airbnb"}},{{/if_eq}} - }{{#if_eq lintConfig "airbnb"}},{{/if_eq}} -}{{#if_eq lintConfig "airbnb"}};{{/if_eq}} diff --git a/template/src/pages/logs/main.json b/template/src/pages/logs/main.json new file mode 100644 index 0000000..12ef72f --- /dev/null +++ b/template/src/pages/logs/main.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "查看启动日志" +}