Skip to content

Commit

Permalink
Merge pull request #50 from mpvue/feature/platform
Browse files Browse the repository at this point in the history
update: 增加配置选项,可制定构建平台
  • Loading branch information
hucq authored Nov 1, 2018
2 parents 89c6a77 + d8186b0 commit 8a1ec68
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 15 deletions.
1 change: 1 addition & 0 deletions template/build/build.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
1 change: 1 addition & 0 deletions template/build/dev-server.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 2 additions & 1 deletion template/build/vue-loader.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ module.exports = {
source: 'src',
img: 'src',
image: 'xlink:href'
}
},
fileExt: config.build.fileExt
}
8 changes: 3 additions & 5 deletions template/build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -77,9 +77,7 @@ module.exports = {
'babel-loader',
{
loader: 'mpvue-loader',
options: {
checkMPEntry: true
}
options: Object.assign({checkMPEntry: true}, vueLoaderConfig)
},
]
},
Expand Down Expand Up @@ -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: ['.*']
}
])
Expand Down
2 changes: 1 addition & 1 deletion template/build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion template/build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 21 additions & 4 deletions template/config/index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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'),
Expand All @@ -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
}
}
12 changes: 9 additions & 3 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand Down

0 comments on commit 8a1ec68

Please sign in to comment.