目的:同時編譯多套代碼,一次修改,同時預覽不一樣平臺小程序在項目根文件夾下 config/index.js 中 新增css
const outputRootStrtegy = { h5: 'dist_h5', weapp: 'dist_weapp', alipay: 'dist_alipay', swan: 'dist_swan', ['undefined']: 'dist' } const env = JSON.parse(process.env.npm_config_argv)['cooked'][1].split(':')[1] const outputRoot = outputRootStrtegy[env]
修改 outputRoot 選項的值
完整代碼
config/index.js
const outputRootStrtegy = { h5: 'dist_h5', weapp: 'dist_weapp', alipay: 'dist_alipay', swan: 'dist_swan', ['undefined']: 'dist' } const env = JSON.parse(process.env.npm_config_argv)['cooked'][1].split(':')[1] const outputRoot = outputRootStrtegy[env] const config = { projectName: 'time-paper-mini', date: '2018-12-11', designWidth: 750, deviceRatio: { '640': 2.34 / 2, '750': 1, '828': 1.81 / 2 }, sourceRoot: 'src', outputRoot: outputRoot, plugins: { babel: { sourceMap: true, presets: [ 'env' ], plugins: [ 'transform-decorators-legacy', 'transform-class-properties', 'transform-object-rest-spread' ] } }, defineConstants: {}, copy: { patterns: [], options: {} }, weapp: { module: { postcss: { autoprefixer: { enable: true, config: { browsers: [ 'last 3 versions', 'Android >= 4.1', 'ios >= 8' ] } }, pxtransform: { enable: true, config: {} }, url: { enable: true, config: { limit: 10240 // 設定轉換尺寸上限 } } } } }, h5: { publicPath: '/', staticDirectory: 'static', module: { postcss: { autoprefixer: { enable: true } } }, h5: { esnextModules: ['taro-ui'] } } } module.exports = function (merge) { if (process.env.NODE_ENV === 'development') { return merge({}, config, require('./dev')) } return merge({}, config, require('./prod')) }