Skip to content

Commit b48a60b

Browse files
committed
update: swan support
1 parent 3fcca8f commit b48a60b

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

template/build/webpack.base.conf.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var path = require('path')
22
var fs = require('fs')
33
var utils = require('./utils')
44
var config = require('../config')
5+
var webpack = require('webpack')
6+
var merge = require('webpack-merge')
57
var vueLoaderConfig = require('./vue-loader.conf')
68
var MpvuePlugin = require('webpack-mpvue-asset-plugin')
79
var glob = require('glob')
@@ -26,7 +28,7 @@ const appEntry = { app: resolve('./src/main.js') }
2628
const pagesEntry = getEntry(resolve('./src'), 'pages/**/main.js')
2729
const entry = Object.assign({}, appEntry, pagesEntry)
2830

29-
module.exports = {
31+
let baseWebpackConfig = {
3032
// 如果要自定义生成的 dist 目录里面的文件路径,
3133
// 可以将 entry 写成 {'toPath': 'fromPath'} 的形式,
3234
// toPath 为相对于 dist 的路径, 例:index/demo,则生成的文件地址为 dist/index/demo.js
@@ -108,6 +110,11 @@ module.exports = {
108110
]
109111
},
110112
plugins: [
113+
// api 统一桥协议方案
114+
new webpack.DefinePlugin({
115+
'mpvue': 'global.mpvue',
116+
'mpvuePlatform': 'global.mpvuePlatform'
117+
}),
111118
new MpvuePlugin(),
112119
new CopyWebpackPlugin([{
113120
from: '**/*.json',
@@ -124,3 +131,20 @@ module.exports = {
124131
])
125132
]
126133
}
134+
135+
// 针对百度小程序,由于不支持通过 miniprogramRoot 进行自定义构建完的文件的根路径
136+
// 所以需要将项目根路径下面的 project.swan.json 拷贝到 dist/swan 下
137+
// 然后百度开发者工具将 dist/swan 作为项目根目录打开进行调试
138+
if (process.env.PLATFORM === 'swan') {
139+
baseWebpackConfig = merge(baseWebpackConfig, {
140+
plugins: [
141+
new CopyWebpackPlugin([{
142+
from: path.resolve(__dirname, '../project.swan.json'),
143+
to: path.resolve(config.build.assetsRoot)
144+
}])
145+
]
146+
})
147+
}
148+
149+
module.exports = baseWebpackConfig
150+

template/build/webpack.dev.conf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var merge = require('webpack-merge')
55
var baseWebpackConfig = require('./webpack.base.conf')
66
// var HtmlWebpackPlugin = require('html-webpack-plugin')
77
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
8+
var MpvueVendorPlugin = require('webpack-mpvue-vendor-plugin')
89

910
// copy from ./webpack.prod.conf.js
1011
var path = require('path')
@@ -67,7 +68,7 @@ module.exports = merge(baseWebpackConfig, {
6768
name: 'common/manifest',
6869
chunks: ['common/vendor']
6970
}),
70-
71+
new MpvueVendorPlugin(),
7172
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
7273
// new webpack.HotModuleReplacementPlugin(),
7374
new webpack.NoEmitOnErrorsPlugin(),

template/build/webpack.prod.conf.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var CopyWebpackPlugin = require('copy-webpack-plugin')
99
// var HtmlWebpackPlugin = require('html-webpack-plugin')
1010
var ExtractTextPlugin = require('extract-text-webpack-plugin')
1111
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
12+
var MpvueVendorPlugin = require('webpack-mpvue-vendor-plugin')
1213

1314
var env = {{#if_or unit e2e}}process.env.NODE_ENV === 'testing'
1415
? require('../config/test.env')
@@ -87,7 +88,8 @@ var webpackConfig = merge(baseWebpackConfig, {
8788
new webpack.optimize.CommonsChunkPlugin({
8889
name: 'common/manifest',
8990
chunks: ['common/vendor']
90-
})
91+
}),
92+
new MpvueVendorPlugin()
9193
]
9294
})
9395

template/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@
2525
},
2626
"devDependencies": {
2727
"mpvue-loader": "^1.1.2",
28-
"mpvue-webpack-target": "^1.0.0",
28+
"mpvue-webpack-target": "^1.0.3",
2929
"mpvue-template-compiler": "^1.0.11",
3030
"portfinder": "^1.0.13",
3131
"postcss-mpvue-wxss": "^1.0.0",
3232
"prettier": "~1.12.1",
3333
"px2rpx-loader": "^0.1.10",
3434
"babel-core": "^6.22.1",
3535
"glob": "^7.1.2",
36-
"webpack-mpvue-asset-plugin": "^0.1.1",
36+
"webpack-mpvue-asset-plugin": "^0.1.2",
37+
"webpack-mpvue-vendor-plugin": "^0.0.1",
3738
"relative": "^3.0.2",
3839
{{#lint}}
3940
"babel-eslint": "^8.2.3",

template/package.swan.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"appid": "{{ appid }}",
3+
"setting": {
4+
"urlCheck": false
5+
},
6+
"condition": {
7+
"swan": {
8+
"current": -1,
9+
"list": []
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)