From d8186b02444499515afe50141a74f6934133b8ed Mon Sep 17 00:00:00 2001 From: hucq Date: Thu, 1 Nov 2018 13:27:58 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=80=89=E9=A1=B9=EF=BC=8C=E5=8F=AF=E5=88=B6=E5=AE=9A=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/build/build.js | 1 + template/build/dev-server.js | 1 + template/build/vue-loader.conf.js | 3 ++- template/build/webpack.base.conf.js | 8 +++----- template/build/webpack.dev.conf.js | 2 +- template/build/webpack.prod.conf.js | 2 +- template/config/index.js | 25 +++++++++++++++++++++---- template/package.json | 12 +++++++++--- 8 files changed, 39 insertions(+), 15 deletions(-) diff --git a/template/build/build.js b/template/build/build.js index 430993d..78466e9 100644 --- a/template/build/build.js +++ b/template/build/build.js @@ -1,6 +1,7 @@ require('./check-versions')() process.env.NODE_ENV = 'production' +process.env.PLATFORM = process.argv[process.argv.length - 1] || 'wx' var ora = require('ora') var rm = require('rimraf') diff --git a/template/build/dev-server.js b/template/build/dev-server.js index 2f58ab2..ebf684b 100644 --- a/template/build/dev-server.js +++ b/template/build/dev-server.js @@ -1,5 +1,6 @@ require('./check-versions')() +process.env.PLATFORM = process.argv[process.argv.length - 1] || 'wx' var config = require('../config') if (!process.env.NODE_ENV) { process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) diff --git a/template/build/vue-loader.conf.js b/template/build/vue-loader.conf.js index 4817a80..6e2c04d 100644 --- a/template/build/vue-loader.conf.js +++ b/template/build/vue-loader.conf.js @@ -16,5 +16,6 @@ module.exports = { source: 'src', img: 'src', image: 'xlink:href' - } + }, + fileExt: config.build.fileExt } diff --git a/template/build/webpack.base.conf.js b/template/build/webpack.base.conf.js index a564a80..391e2d0 100644 --- a/template/build/webpack.base.conf.js +++ b/template/build/webpack.base.conf.js @@ -43,7 +43,7 @@ module.exports = { extensions: ['.js', '.vue', '.json'], alias: { {{#if_eq build "standalone"}} - // 'vue$': 'vue/dist/vue.esm.js', + // 'vue$': `vue/dist/${config.build.fileExt.platform}/vue.esm.js`, {{/if_eq}} 'vue': 'mpvue', '@': resolve('src') @@ -77,9 +77,7 @@ module.exports = { 'babel-loader', { loader: 'mpvue-loader', - options: { - checkMPEntry: true - } + options: Object.assign({checkMPEntry: true}, vueLoaderConfig) }, ] }, @@ -120,7 +118,7 @@ module.exports = { new CopyWebpackPlugin([ { from: path.resolve(__dirname, '../static'), - to: path.resolve(__dirname, '../dist/static'), + to: path.resolve(config.build.assetsRoot, './static'), ignore: ['.*'] } ]) diff --git a/template/build/webpack.dev.conf.js b/template/build/webpack.dev.conf.js index af13377..1bbdd40 100644 --- a/template/build/webpack.dev.conf.js +++ b/template/build/webpack.dev.conf.js @@ -43,7 +43,7 @@ module.exports = merge(baseWebpackConfig, { // extract css into its own file new ExtractTextPlugin({ // filename: utils.assetsPath('[name].[contenthash].css') - filename: utils.assetsPath('[name].wxss') + filename: utils.assetsPath(`[name].${config.dev.fileExt.style}`) }), // Compress extracted CSS. We are using this plugin so that possible // duplicated CSS from different components can be deduped. diff --git a/template/build/webpack.prod.conf.js b/template/build/webpack.prod.conf.js index 14c5c72..58bbd79 100644 --- a/template/build/webpack.prod.conf.js +++ b/template/build/webpack.prod.conf.js @@ -40,7 +40,7 @@ var webpackConfig = merge(baseWebpackConfig, { // extract css into its own file new ExtractTextPlugin({ // filename: utils.assetsPath('[name].[contenthash].css') - filename: utils.assetsPath('[name].wxss') + filename: utils.assetsPath(`[name].${config.build.fileExt.style}`) }), // Compress extracted CSS. We are using this plugin so that possible // duplicated CSS from different components can be deduped. diff --git a/template/config/index.js b/template/config/index.js index 5678f57..6da3bf4 100644 --- a/template/config/index.js +++ b/template/config/index.js @@ -1,11 +1,26 @@ // see http://vuejs-templates.github.io/webpack for documentation. var path = require('path') +var fileExtConfig = { + swan: { + template: 'swan', + script: 'js', + style: 'css', + platform: 'swan' + }, + wx: { + template: 'wxmp', + script: 'js', + style: 'wxss', + platform: 'wx' + } +} +var fileExt = fileExtConfig[process.env.PLATFORM] module.exports = { build: { env: require('./prod.env'), - index: path.resolve(__dirname, '../dist/index.html'), - assetsRoot: path.resolve(__dirname, '../dist'), + index: path.resolve(__dirname, `../dist/${fileExt.platform}/index.html`), + assetsRoot: path.resolve(__dirname, `../dist/${fileExt.platform}`), assetsSubDirectory: '', assetsPublicPath: '/', productionSourceMap: false, @@ -19,7 +34,8 @@ module.exports = { // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off - bundleAnalyzerReport: process.env.npm_config_report + bundleAnalyzerReport: process.env.npm_config_report, + fileExt: fileExt }, dev: { env: require('./dev.env'), @@ -34,6 +50,7 @@ module.exports = { // (https://github.com/webpack/css-loader#sourcemaps) // In our experience, they generally work as expected, // just be aware of this issue when enabling this option. - cssSourceMap: false + cssSourceMap: false, + fileExt: fileExt } } diff --git a/template/package.json b/template/package.json index 8594c58..86110c2 100644 --- a/template/package.json +++ b/template/package.json @@ -5,9 +5,15 @@ "author": "{{ author }}", "private": true, "scripts": { - "dev": "node build/dev-server.js", - "start": "node build/dev-server.js", - "build": "node build/build.js"{{#unit}}, + "dev:wx": "node build/dev-server.js wx", + "start:wx": "npm run dev:wx", + "build:wx": "node build/build.js wx", + "dev:swan": "node build/dev-server.js swan", + "start:swan": "npm run dev:swan", + "build:swan": "node build/build.js swan" + "dev": "node build/dev-server.js wx", + "start": "npm run dev", + "build": "node build/build.js wx"{{#unit}}, "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run"{{/unit}}{{#e2e}}, "e2e": "node test/e2e/runner.js"{{/e2e}}{{#if_or unit e2e}}, "test": "{{#unit}}npm run unit{{/unit}}{{#unit}}{{#e2e}} && {{/e2e}}{{/unit}}{{#e2e}}npm run e2e{{/e2e}}"{{/if_or}}{{#lint}},