taro

1. 发布后缓存问题(仅针对h5)

enableExtract: true,

output: {

      filename: 'js/[name].[hash:8].js',

      chunkFilename: 'js/[name].[chunkhash:8].js'

},

miniCssExtractPluginOption: {

      filename: 'css/[name].[hash:8].css',

      chunkFilename: 'css/[id].[chunkhash:8].css'

}


配置图例

参考官方文档:https://nervjs.github.io/taro/docs/config-detail.html#h5minicssextractpluginoption


2. 全局变量配置

npm install --save-dev cross-env

配置全局变量

参考官方文档: https://nervjs.github.io/taro/docs/config-detail.html#defineconstants



3. h5 添加vConsole

<script src="https://res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/vconsole/3.0.0/vconsole.min.js" type="text/javascript"></script>

<script type="text/javascript">

    new VConsole();

  </script>



4. 版本切换升级

1. 更新cli

npm install -g @tarojs/cli@[版本号]   或 $ taro update self [version]   或  yarn global add @tarojs/cli@[version]

2. 更新项目中 Taro 相关的依赖

$ taro update project [version]

如命令更新失败,需要在 package.json 文件手动更新依赖版本,然后重新安装依赖。

这里有详细说明

https://taro-docs.jd.com/taro/docs/GETTING-STARTED.html#%E6%9B%B4%E6%96%B0



5. 编译错误:

报错:Module build failed (from ./node_modules/@tarojs/webpack-runner/node_modules/babel-loader/lib/index.js),如下图:

编译错误示例

解决方案:

node版本问题,如果同时进行的项目必须用不同的node版本,那就下载个nvm

详情参考下://www.greatytc.com/p/87466f802fea

6. 线上环境去掉vConsole

npm install babel-plugin-transform-remove-console --save-dev


let plugins = [

    'transform-decorators-legacy',

    'transform-class-properties',

    'transform-object-rest-spread',

    ['transform-runtime', {

        "helpers": false,

        "polyfill": false,

        "regenerator": true,

        "moduleName": 'babel-runtime'

    }]

];

if (process.env.ENVIRONMENT === 'product') {

    plugins.push('transform-remove-console');

}

7. npm run dev 报错:getaddrinfo ENOTFOUND localhost和解决方法

https://segmentfault.com/a/1190000015274463?utm_source=tag-newest

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容