Skip to content

Commit

Permalink
update: swan support
Browse files Browse the repository at this point in the history
  • Loading branch information
hucq committed Dec 4, 2018
1 parent 3fcca8f commit b48a60b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
26 changes: 25 additions & 1 deletion template/build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var path = require('path')
var fs = require('fs')
var utils = require('./utils')
var config = require('../config')
var webpack = require('webpack')
var merge = require('webpack-merge')
var vueLoaderConfig = require('./vue-loader.conf')
var MpvuePlugin = require('webpack-mpvue-asset-plugin')
var glob = require('glob')
Expand All @@ -26,7 +28,7 @@ const appEntry = { app: resolve('./src/main.js') }
const pagesEntry = getEntry(resolve('./src'), 'pages/**/main.js')
const entry = Object.assign({}, appEntry, pagesEntry)

module.exports = {
let baseWebpackConfig = {
// 如果要自定义生成的 dist 目录里面的文件路径,
// 可以将 entry 写成 {'toPath': 'fromPath'} 的形式,
// toPath 为相对于 dist 的路径, 例:index/demo,则生成的文件地址为 dist/index/demo.js
Expand Down Expand Up @@ -108,6 +110,11 @@ module.exports = {
]
},
plugins: [
// api 统一桥协议方案
new webpack.DefinePlugin({
'mpvue': 'global.mpvue',
'mpvuePlatform': 'global.mpvuePlatform'
}),
new MpvuePlugin(),
new CopyWebpackPlugin([{
from: '**/*.json',
Expand All @@ -124,3 +131,20 @@ module.exports = {
])
]
}

// 针对百度小程序,由于不支持通过 miniprogramRoot 进行自定义构建完的文件的根路径
// 所以需要将项目根路径下面的 project.swan.json 拷贝到 dist/swan 下
// 然后百度开发者工具将 dist/swan 作为项目根目录打开进行调试
if (process.env.PLATFORM === 'swan') {
baseWebpackConfig = merge(baseWebpackConfig, {
plugins: [
new CopyWebpackPlugin([{
from: path.resolve(__dirname, '../project.swan.json'),
to: path.resolve(config.build.assetsRoot)
}])
]
})
}

module.exports = baseWebpackConfig

3 changes: 2 additions & 1 deletion template/build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var merge = require('webpack-merge')
var baseWebpackConfig = require('./webpack.base.conf')
// var HtmlWebpackPlugin = require('html-webpack-plugin')
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
var MpvueVendorPlugin = require('webpack-mpvue-vendor-plugin')

// copy from ./webpack.prod.conf.js
var path = require('path')
Expand Down Expand Up @@ -67,7 +68,7 @@ module.exports = merge(baseWebpackConfig, {
name: 'common/manifest',
chunks: ['common/vendor']
}),

new MpvueVendorPlugin(),
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
// new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
Expand Down
4 changes: 3 additions & 1 deletion template/build/webpack.prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var CopyWebpackPlugin = require('copy-webpack-plugin')
// var HtmlWebpackPlugin = require('html-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
var MpvueVendorPlugin = require('webpack-mpvue-vendor-plugin')

var env = {{#if_or unit e2e}}process.env.NODE_ENV === 'testing'
? require('../config/test.env')
Expand Down Expand Up @@ -87,7 +88,8 @@ var webpackConfig = merge(baseWebpackConfig, {
new webpack.optimize.CommonsChunkPlugin({
name: 'common/manifest',
chunks: ['common/vendor']
})
}),
new MpvueVendorPlugin()
]
})

Expand Down
5 changes: 3 additions & 2 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
},
"devDependencies": {
"mpvue-loader": "^1.1.2",
"mpvue-webpack-target": "^1.0.0",
"mpvue-webpack-target": "^1.0.3",
"mpvue-template-compiler": "^1.0.11",
"portfinder": "^1.0.13",
"postcss-mpvue-wxss": "^1.0.0",
"prettier": "~1.12.1",
"px2rpx-loader": "^0.1.10",
"babel-core": "^6.22.1",
"glob": "^7.1.2",
"webpack-mpvue-asset-plugin": "^0.1.1",
"webpack-mpvue-asset-plugin": "^0.1.2",
"webpack-mpvue-vendor-plugin": "^0.0.1",
"relative": "^3.0.2",
{{#lint}}
"babel-eslint": "^8.2.3",
Expand Down
12 changes: 12 additions & 0 deletions template/package.swan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"appid": "{{ appid }}",
"setting": {
"urlCheck": false
},
"condition": {
"swan": {
"current": -1,
"list": []
}
}
}

0 comments on commit b48a60b

Please sign in to comment.