Skip to content

Commit d8186b0

Browse files
committed
update: 增加配置选项,可制定构建平台
1 parent 89c6a77 commit d8186b0

File tree

8 files changed

+39
-15
lines changed

8 files changed

+39
-15
lines changed

template/build/build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require('./check-versions')()
22

33
process.env.NODE_ENV = 'production'
4+
process.env.PLATFORM = process.argv[process.argv.length - 1] || 'wx'
45

56
var ora = require('ora')
67
var rm = require('rimraf')

template/build/dev-server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require('./check-versions')()
22

3+
process.env.PLATFORM = process.argv[process.argv.length - 1] || 'wx'
34
var config = require('../config')
45
if (!process.env.NODE_ENV) {
56
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)

template/build/vue-loader.conf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ module.exports = {
1616
source: 'src',
1717
img: 'src',
1818
image: 'xlink:href'
19-
}
19+
},
20+
fileExt: config.build.fileExt
2021
}

template/build/webpack.base.conf.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = {
4343
extensions: ['.js', '.vue', '.json'],
4444
alias: {
4545
{{#if_eq build "standalone"}}
46-
// 'vue$': 'vue/dist/vue.esm.js',
46+
// 'vue$': `vue/dist/${config.build.fileExt.platform}/vue.esm.js`,
4747
{{/if_eq}}
4848
'vue': 'mpvue',
4949
'@': resolve('src')
@@ -77,9 +77,7 @@ module.exports = {
7777
'babel-loader',
7878
{
7979
loader: 'mpvue-loader',
80-
options: {
81-
checkMPEntry: true
82-
}
80+
options: Object.assign({checkMPEntry: true}, vueLoaderConfig)
8381
},
8482
]
8583
},
@@ -120,7 +118,7 @@ module.exports = {
120118
new CopyWebpackPlugin([
121119
{
122120
from: path.resolve(__dirname, '../static'),
123-
to: path.resolve(__dirname, '../dist/static'),
121+
to: path.resolve(config.build.assetsRoot, './static'),
124122
ignore: ['.*']
125123
}
126124
])

template/build/webpack.dev.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = merge(baseWebpackConfig, {
4343
// extract css into its own file
4444
new ExtractTextPlugin({
4545
// filename: utils.assetsPath('[name].[contenthash].css')
46-
filename: utils.assetsPath('[name].wxss')
46+
filename: utils.assetsPath(`[name].${config.dev.fileExt.style}`)
4747
}),
4848
// Compress extracted CSS. We are using this plugin so that possible
4949
// duplicated CSS from different components can be deduped.

template/build/webpack.prod.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var webpackConfig = merge(baseWebpackConfig, {
4040
// extract css into its own file
4141
new ExtractTextPlugin({
4242
// filename: utils.assetsPath('[name].[contenthash].css')
43-
filename: utils.assetsPath('[name].wxss')
43+
filename: utils.assetsPath(`[name].${config.build.fileExt.style}`)
4444
}),
4545
// Compress extracted CSS. We are using this plugin so that possible
4646
// duplicated CSS from different components can be deduped.

template/config/index.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
// see http://vuejs-templates.github.io/webpack for documentation.
22
var path = require('path')
3+
var fileExtConfig = {
4+
swan: {
5+
template: 'swan',
6+
script: 'js',
7+
style: 'css',
8+
platform: 'swan'
9+
},
10+
wx: {
11+
template: 'wxmp',
12+
script: 'js',
13+
style: 'wxss',
14+
platform: 'wx'
15+
}
16+
}
17+
var fileExt = fileExtConfig[process.env.PLATFORM]
318

419
module.exports = {
520
build: {
621
env: require('./prod.env'),
7-
index: path.resolve(__dirname, '../dist/index.html'),
8-
assetsRoot: path.resolve(__dirname, '../dist'),
22+
index: path.resolve(__dirname, `../dist/${fileExt.platform}/index.html`),
23+
assetsRoot: path.resolve(__dirname, `../dist/${fileExt.platform}`),
924
assetsSubDirectory: '',
1025
assetsPublicPath: '/',
1126
productionSourceMap: false,
@@ -19,7 +34,8 @@ module.exports = {
1934
// View the bundle analyzer report after build finishes:
2035
// `npm run build --report`
2136
// Set to `true` or `false` to always turn it on or off
22-
bundleAnalyzerReport: process.env.npm_config_report
37+
bundleAnalyzerReport: process.env.npm_config_report,
38+
fileExt: fileExt
2339
},
2440
dev: {
2541
env: require('./dev.env'),
@@ -34,6 +50,7 @@ module.exports = {
3450
// (https://github.com/webpack/css-loader#sourcemaps)
3551
// In our experience, they generally work as expected,
3652
// just be aware of this issue when enabling this option.
37-
cssSourceMap: false
53+
cssSourceMap: false,
54+
fileExt: fileExt
3855
}
3956
}

template/package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
"author": "{{ author }}",
66
"private": true,
77
"scripts": {
8-
"dev": "node build/dev-server.js",
9-
"start": "node build/dev-server.js",
10-
"build": "node build/build.js"{{#unit}},
8+
"dev:wx": "node build/dev-server.js wx",
9+
"start:wx": "npm run dev:wx",
10+
"build:wx": "node build/build.js wx",
11+
"dev:swan": "node build/dev-server.js swan",
12+
"start:swan": "npm run dev:swan",
13+
"build:swan": "node build/build.js swan"
14+
"dev": "node build/dev-server.js wx",
15+
"start": "npm run dev",
16+
"build": "node build/build.js wx"{{#unit}},
1117
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run"{{/unit}}{{#e2e}},
1218
"e2e": "node test/e2e/runner.js"{{/e2e}}{{#if_or unit e2e}},
1319
"test": "{{#unit}}npm run unit{{/unit}}{{#unit}}{{#e2e}} && {{/e2e}}{{/unit}}{{#e2e}}npm run e2e{{/e2e}}"{{/if_or}}{{#lint}},

0 commit comments

Comments
 (0)