Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

taro与原生小程序混合开发打包分包文件被打包到主包common #8645

Closed
wangkefu opened this issue Feb 4, 2021 · 3 comments
Closed
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-2 Version - 2.x

Comments

@wangkefu
Copy link

wangkefu commented Feb 4, 2021

相关平台

微信小程序

小程序基础库: 2.14.4
使用框架: React

复现步骤

项目整体是taro项目 分包packageC里全是原生小程序结构,打包后packageC里的util文件被打包到了common.js。我通过设置cachegroups和addChunkPages抽离分包公共文件 但是重新打包后进入分包页面时报错VM5800 WAService.js:2 SyntaxError: Unexpected identifier SyntaxError: Unexpected token export

期望结果

正常进入分包

实际结果

报错了。

环境信息


👽 Taro v2.2.11


  Taro CLI 2.2.11 environment info:
    System:
      OS: macOS 10.14
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 12.3.1 - /usr/local/bin/node
      npm: 6.14.10 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 2.2.11 => 2.2.11 
      @tarojs/components: 2.2.11 => 2.2.11 
      @tarojs/mini-runner: 2.2.11 => 2.2.11 
      @tarojs/plugin-babel: 2.2.11 => 2.2.11 
      @tarojs/plugin-csso: 2.2.11 => 2.2.11 
      @tarojs/plugin-sass: 2.2.11 => 2.2.11 
      @tarojs/plugin-uglify: ^2.2.7 => 2.2.10 
      @tarojs/redux: 2.2.11 => 2.2.11 
      @tarojs/redux-h5: 2.2.11 => 2.2.11 
      @tarojs/router: 2.2.11 => 2.2.11 
      @tarojs/taro: 2.2.11 => 2.2.11 
      @tarojs/taro-alipay: 2.2.11 => 2.2.11 
      @tarojs/taro-h5: 2.2.11 => 2.2.11 
      @tarojs/taro-swan: 2.2.11 => 2.2.11 
      @tarojs/taro-tt: 2.2.11 => 2.2.11 
      @tarojs/taro-weapp: 2.2.11 => 2.2.11 
      @tarojs/webpack-runner: 2.2.11 => 2.2.11 
      eslint-config-taro: 2.2.11 => 2.2.11 
      eslint-plugin-taro: 2.2.11 => 2.2.11 
      nerv-devtools: ^1.5.7 => 1.5.7 
      nervjs: ^1.5.7 => 1.5.7 
      taro-ui: ^2.2.1 => 2.3.4 

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-2 Version - 2.x labels Feb 4, 2021
@Chen-jj
Copy link
Contributor

Chen-jj commented Feb 4, 2021

目测配错了,可以上个 demo 看看

@wangkefu
Copy link
Author

wangkefu commented Feb 4, 2021

webpackChain(chain, webpack) { chain.merge({ optimization: { splitChunks: { cacheGroups: { ddd:{ name: "packageC/ddds", priority: 1000, test(module) { if ( /src[\\/]packageC[\\/]utils/.test(module.resource) ) { return true; } }, }, lodash: { name: "lodash", priority: 1000, test(module) { return /node_modules[\\/]lodash/.test(module.context); } }, moment: { name: "date-fns", priority: 1000, test(module) { return /node_modules[\\/]date-fns/.test(module.context); } } } } } }) // if (isPro) { // chain.plugin('analyzer') // .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, []) // } chain.plugin('IgnorePlugin') .use(webpack.IgnorePlugin, [/^\.\/locale$/, /date-fns$/]) chain.plugin('LodashModuleReplacementPlugin') .use(require('lodash-webpack-plugin'), [{ 'coercions': true, 'paths': true }]) }, addChunkPages(pages, pagesNames) { pages.set("packageC/pages", ["ddd"]); },
以上packageC相关和addchunkpages是我配置的。

@wangkefu
Copy link
Author

wangkefu commented Feb 4, 2021

目测配错了,可以上个 demo 看看

const PKGCChunkName = 'packageC/subCommon';
addChunkPages(pages, pagesNames) {
pages.set("packageC/pages/edit_post/edit_post", [PKGCChunkName]);
},
webpackChain(chain, webpack) { chain.merge({ optimization: { splitChunks: { cacheGroups: { PKGCChunkName:{ name: PKGCChunkName, priority: 1000, test(module) { if ( /src[\\/]packageC[\\/]utils/.test(module.resource) ) { return true; } }, },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-2 Version - 2.x
Projects
None yet
Development

No branches or pull requests

2 participants