first commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
// eslint-disable-next-line import/no-commonjs
|
||||
module.exports = {
|
||||
env: {
|
||||
NODE_ENV: '"development"',
|
||||
},
|
||||
defineConstants: {},
|
||||
mini: {},
|
||||
h5: {},
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
/* eslint-disable import/no-commonjs */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const npath = require("path");
|
||||
const pkg = require("../package.json");
|
||||
const miniChain = require("./webpack/miniChain");
|
||||
const h5Chain = require("./webpack/h5Chain");
|
||||
|
||||
process.env.TARO_ENV = process.env.TARO_ENV ?? "weapp"
|
||||
process.env.NODE_ENV = process.env.NODE_ENV ?? 'production'
|
||||
process.env.API_ENV = process.env.API_ENV ?? 'real'
|
||||
|
||||
const config = {
|
||||
projectName: pkg.name,
|
||||
date: "2022-8-10",
|
||||
designWidth: 750,
|
||||
deviceRatio: {
|
||||
640: 2.34 / 2,
|
||||
750: 1,
|
||||
828: 1.81 / 2,
|
||||
},
|
||||
sourceRoot: "src",
|
||||
outputRoot: process.env.TARO_ENV === "h5" ? "build" : process.env.TARO_ENV,
|
||||
alias: {
|
||||
"@": npath.resolve(process.cwd(), "src"),
|
||||
},
|
||||
defineConstants: {},
|
||||
copy: {
|
||||
patterns: [],
|
||||
options: {},
|
||||
},
|
||||
framework: "react",
|
||||
compiler: "webpack5",
|
||||
cache: {
|
||||
enable: false, // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
|
||||
},
|
||||
mini: {
|
||||
webpackChain(chain) {
|
||||
miniChain(chain);
|
||||
},
|
||||
lessLoaderOption: {
|
||||
lessOptions: {
|
||||
modifyVars: {
|
||||
hack: `true; @import "${npath.join(
|
||||
process.cwd(),
|
||||
"src/styles/index.less"
|
||||
)}";`,
|
||||
},
|
||||
},
|
||||
// 适用于全局引入样式
|
||||
// additionalData: "@import '~/src/styles/index.less';",
|
||||
},
|
||||
postcss: {
|
||||
pxtransform: {
|
||||
enable: true,
|
||||
config: {},
|
||||
},
|
||||
url: {
|
||||
enable: true,
|
||||
config: {
|
||||
limit: 1024, // 设定转换尺寸上限
|
||||
},
|
||||
},
|
||||
cssModules: {
|
||||
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
||||
config: {
|
||||
namingPattern: "module", // 转换模式,取值为 global/module
|
||||
generateScopedName: "[name]__[local]___[hash:base64:5]",
|
||||
},
|
||||
},
|
||||
},
|
||||
miniCssExtractPluginOption: {
|
||||
ignoreOrder: true,
|
||||
},
|
||||
},
|
||||
h5: {
|
||||
webpackChain(chain) {
|
||||
h5Chain(chain);
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
chain.performance.maxEntrypointSize(1000000).maxAssetSize(512000);
|
||||
}
|
||||
},
|
||||
esnextModules: [/@antmjs[\\/]vantui/],
|
||||
lessLoaderOption: {
|
||||
lessOptions: {
|
||||
modifyVars: {
|
||||
// 或者可以通过 less 文件覆盖(文件路径为绝对路径)
|
||||
hack: `true; @import "${npath.join(
|
||||
process.cwd(),
|
||||
"src/styles/index.less"
|
||||
)}";`,
|
||||
},
|
||||
},
|
||||
},
|
||||
router: {
|
||||
mode: "browser",
|
||||
},
|
||||
devServer: {
|
||||
hot: false,
|
||||
},
|
||||
publicPath: "/",
|
||||
staticDirectory: "static",
|
||||
postcss: {
|
||||
autoprefixer: {
|
||||
enable: true,
|
||||
config: {},
|
||||
},
|
||||
cssModules: {
|
||||
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
||||
config: {
|
||||
namingPattern: "module", // 转换模式,取值为 global/module
|
||||
generateScopedName: "[name]__[local]___[hash:base64:5]",
|
||||
},
|
||||
},
|
||||
},
|
||||
miniCssExtractPluginOption: {
|
||||
ignoreOrder: true,
|
||||
filename: "assets/css/[name].css",
|
||||
chunkFilename: "assets/css/chunk/[name].css",
|
||||
},
|
||||
},
|
||||
rn: {
|
||||
appName: "taroDemo",
|
||||
postcss: {
|
||||
cssModules: {
|
||||
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
["@tarojs/plugin-framework-react", { reactMode: "concurrent" }],
|
||||
"@tarojs/plugin-platform-alipay-dd",
|
||||
["@tarojs/plugin-platform-kwai"],
|
||||
],
|
||||
};
|
||||
|
||||
module.exports = function (merge) {
|
||||
return merge({}, config, require(`./${process.env.NODE_ENV}`));
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
// eslint-disable-next-line import/no-commonjs
|
||||
module.exports = {
|
||||
env: {
|
||||
NODE_ENV: '"production"',
|
||||
},
|
||||
defineConstants: {},
|
||||
mini: {},
|
||||
h5: {
|
||||
/**
|
||||
* WebpackChain 插件配置
|
||||
* @docs https://github.com/neutrinojs/webpack-chain
|
||||
*/
|
||||
// webpackChain (chain) {
|
||||
// /**
|
||||
// * 如果 h5 端编译后体积过大,可以使用 webpack-bundle-analyzer 插件对打包体积进行分析。
|
||||
// * @docs https://github.com/webpack-contrib/webpack-bundle-analyzer
|
||||
// */
|
||||
// chain.plugin('analyzer')
|
||||
// .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
|
||||
// /**
|
||||
// * 如果 h5 端首屏加载时间过长,可以使用 prerender-spa-plugin 插件预加载首页。
|
||||
// * @docs https://github.com/chrisvfritz/prerender-spa-plugin
|
||||
// */
|
||||
// const path = require('path')
|
||||
// const Prerender = require('prerender-spa-plugin')
|
||||
// const staticDir = path.join(__dirname, '..', 'dist')
|
||||
// chain
|
||||
// .plugin('prerender')
|
||||
// .use(new Prerender({
|
||||
// staticDir,
|
||||
// routes: [ '/pages/index/index' ],
|
||||
// postProcess: (context) => ({ ...context, outputPath: path.join(staticDir, 'index.html') })
|
||||
// }))
|
||||
// }
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
module.exports = function (chain) {
|
||||
// taro内部的配置:scriptRule.exclude = [filename => /css-loader/.test(filename) || (/node_modules/.test(filename) && !(/taro/.test(filename)))];
|
||||
// 下面重写exclude的配置,部分三方包需要babel,包括taro、@antmjs等
|
||||
// 根据exclude可以看出,千万不要在项目名称上面带上taro字样,否则所有引用到node_modules的包都会重新被编译一次
|
||||
// 以下配置将不再使用usage配置,因为根据小程序官方描述,ios9开始基本都已支持了,浏览器可以使用polyfill.io 国内可以用阿里云版的,index.html有引用
|
||||
|
||||
/*
|
||||
* 如果babel.config.js设置useBuiltIns:usage
|
||||
* /tarojs[\\/](runtime|shared|plugin-platform|components)/.test(filename) 应该被exculde
|
||||
* /tarojs[\\/](runtime|shared|plugin-platform)/.test(filename) 应该单独babel 且设置useBuiltIns:false
|
||||
*/
|
||||
chain.module
|
||||
.rule('script')
|
||||
.exclude.clear()
|
||||
.add(
|
||||
(filename) =>
|
||||
/css-loader/.test(filename) ||
|
||||
(/node_modules/.test(filename) &&
|
||||
!/(taro)|(inversify)|(@antmjs)|(react-spring)|(recoil)|(buffer)|(qrcode)/.test(
|
||||
filename,
|
||||
)),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/* eslint-disable import/no-commonjs */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const H5FixPlugin = require('@antmjs/plugin-h5-fix')
|
||||
const commonChain = require('./commonChain')
|
||||
|
||||
module.exports = function (chain) {
|
||||
chain.plugin('H5FixPlugin').use(new H5FixPlugin())
|
||||
commonChain(chain)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/* eslint-disable import/no-commonjs */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const MiniFixPlugin = require('@antmjs/plugin-mini-fix')
|
||||
const GlobalFixPlugin = require('@antmjs/plugin-global-fix')
|
||||
const commonChain = require('./commonChain')
|
||||
|
||||
module.exports = function (chain) {
|
||||
// add @antmjs/plugin-mini-fix and @antmjs/mini-fix
|
||||
// 解决微信小程序和抖音小程序的path上的params没有自动decode的问题,支付宝和钉钉是有decode过的
|
||||
// 这个问题是因为微信抖音和支付宝钉钉原生小程序的返回结果就是不一致的,Taro目前是没有去处理的
|
||||
chain.plugin('MiniFixPlugin').use(new MiniFixPlugin())
|
||||
|
||||
//解决支付宝小程序、钉钉小程序、百度小程序没有暴露全局变量global的问题
|
||||
chain.plugin('GlobalFixPlugin').use(new GlobalFixPlugin())
|
||||
commonChain(chain)
|
||||
}
|
||||
Reference in New Issue
Block a user