Authored by lea guo

赠加babel-plugin-lodash插件

... ... @@ -23,7 +23,7 @@ import RecommendGoods from "./components/recommend-goods";
import RecommendFreeGoods from "./components/recommend-free-goods";
import { createNamespacedHelpers } from "vuex";
const { mapState } = createNamespacedHelpers("freeCharge");
const { mapState, mapActions } = createNamespacedHelpers("zeroHelp");
export default {
components: {
... ... @@ -38,7 +38,13 @@ export default {
"http://img10.static.yhbimg.com/yhb-img01/2019/08/20/17/01bb10aa4f373016cc5e7963b1d6c1182f.jpg"
};
},
computed: {}
computed: {},
mounted() {
this.fetchPoolGoods();
},
methods: {
...mapActions(["fetchPoolGoods"])
}
};
</script>
... ...
... ... @@ -17,7 +17,7 @@ export default function() {
pageSize: 10,
total: 0,
page: 0,
filterId: 0
filterId: 0,
},
use: {
couponList: [],
... ... @@ -25,7 +25,7 @@ export default function() {
pageSize: 10,
total: 0,
page: 0,
filterId: 0
filterId: 0,
},
overtime: {
couponList: [],
... ... @@ -33,13 +33,13 @@ export default function() {
pageSize: 10,
total: 0,
page: 0,
filterId: 0
}
filterId: 0,
},
},
num: {
notuse: 0,
use: 0,
overtime: 0
overtime: 0,
},
ufoList: [],
filterList: [],
... ... @@ -48,7 +48,11 @@ export default function() {
mutations,
getters: {
getNum(state) {
return [handleNum(state.num.notuse), handleNum(state.num.use), handleNum(state.num.overtime)];
return [
handleNum(state.num.notuse),
handleNum(state.num.use),
handleNum(state.num.overtime),
];
},
getNotUseList(state) {
return state.yohoList.notuse.couponList;
... ... @@ -59,6 +63,6 @@ export default function() {
getOvertimeList(state) {
return state.yohoList.overtime.couponList;
},
}
},
};
}
... ...
export const FETCH_ZERO_HELP_OTHER_GOODS = 'FETCH_ZERO_HELP_OTHER_GOODS';
export const FETCH_POOL_GOODS = 'FETCH_POOL_GOODS';
export const FETCH_ZERO_HELP_COMMAND = 'FETCH_ZERO_HELP_COMMAND';
export const FETCH_INIT = 'FETCH_INIT';
export const IS_LOADING = 'IS_LOADING';
const productPool = 730;
import { isArray, isEmpty } from 'lodash';
export default {
namespaced: true,
state: {
recommendGoods: [],
recommendFreeChargeGoods: [],
isLoading: false,
poolGoodsInfo: {
page: 0,
pageSize: 10,
total: 0,
goodsList: [],
},
recommendFreeChargeGoods: {},
},
getters: {},
actions: {
async fetchRecommendGoods() {},
async init({ commit }) {
commit(IS_LOADING, true);
commit('FETCH_INIT');
},
// 获取资源池商品
async fetchPoolGoods({ commit, state: { poolGoodsInfo } }) {
let { total, pageSize, page } = poolGoodsInfo;
if (page * pageSize > total) {
return;
}
page++;
let res = await this.$api.get('/api/zero/help/poll/productList', {
page,
limit: pageSize,
productPool,
});
if (res.code !== 200) {
commit(IS_LOADING, false);
return;
}
/**
* 数据格式兼容
* res: {
* code: 200,
* data: [] | {total, page_total, page_size, page, product_list}
* }
* 无数据返回 []
*/
if (isArray(res.data) && isEmpty(res)) {
res = { ...res, data: { product_list: [], page } };
}
commit(FETCH_POOL_GOODS, res);
},
async fetchZeroHelpOtherGoods() {},
async fetchZeroHelpCommand() {},
async fetchZeroHelpInfo() {
// const res = await this.$api.get('')
},
},
mutations: {
[FETCH_INIT](state, data) {
state.recommendGoods = data;
},
[IS_LOADING](state, status = false) {
state.isLoading = status;
},
// eslint-disable-next-line no-unused-vars
[FETCH_POOL_GOODS]({ poolGoodsInfo }, res) {
poolGoodsInfo = { ...poolGoodsInfo, res };
},
},
mutations: {},
};
... ...
module.exports = {
presets: [
['@babel/preset-env', {
[
'@babel/preset-env',
{
modules: false,
useBuiltIns: 'usage'
}]
useBuiltIns: 'usage',
},
],
],
sourceType: 'unambiguous',
plugins: [
'transform-vue-jsx',
'@babel/transform-async-to-generator',
'@babel/proposal-object-rest-spread',
'@babel/syntax-dynamic-import'
]
'@babel/syntax-dynamic-import',
'lodash',
],
};
... ...
... ... @@ -4,6 +4,8 @@ const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
var PostCompilePlugin = require('webpack-post-compile-plugin');
var TransformModulesPlugin = require('webpack-transform-modules-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
var LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const pkg = require('../package.json');
const isProd = process.env.NODE_ENV === 'production';
const distDir = path.join(__dirname, `../dist/statics/${pkg.name}`);
... ... @@ -12,25 +14,21 @@ function resolve(dir) {
return path.join(__dirname, '..', dir);
}
const webpackConfig = {
mode: isProd ? 'production' : 'development',
output: {
filename: 'static/js/[name].[chunkhash].js',
path: distDir,
chunkFilename: 'static/js/[name].[chunkhash].js',
publicPath: isProd ? '//cdn.yoho.cn/yoho-app-web/' : '/'
publicPath: isProd ? '//cdn.yoho.cn/yoho-app-web/' : '/',
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
vue$: 'vue/dist/vue.runtime.esm.js',
'lottie-web': 'lottie-web/build/player/lottie_light.min.js'
'lottie-web': 'lottie-web/build/player/lottie_light.min.js',
},
modules: [
path.join(__dirname, '../apps'),
'node_modules'
]
modules: [path.join(__dirname, '../apps'), 'node_modules'],
},
module: {
rules: [
... ... @@ -40,20 +38,20 @@ const webpackConfig = {
loader: 'vue-loader',
options: {
extractCSS: isProd,
}
},
},
},
{
resourceQuery: /blockType=client/,
use: 'babel-loader',
exclude: /node_modules/
exclude: /node_modules/,
},
{
test: /\.js$/,
use: 'babel-loader',
include: [resolve('apps'), /cube-ui/]
include: [resolve('apps'), /cube-ui/],
},
]
],
},
plugins: [
new webpack.HashedModuleIdsPlugin(),
... ... @@ -61,9 +59,8 @@ const webpackConfig = {
new PostCompilePlugin(),
new TransformModulesPlugin(),
new VueLoaderPlugin(),
]
new LodashModuleReplacementPlugin(),
],
};
module.exports = webpackConfig;
... ...
... ... @@ -24,10 +24,6 @@
"cube-ui": {
"transform": "cube-ui/src/modules/${member}",
"kebabCase": true
},
"lodash": {
"transform": "lodash/${member}",
"kebabCase": true
}
},
"dependencies": {
... ... @@ -82,6 +78,7 @@
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.4",
"babel-plugin-import": "^1.11.0",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-imports": "^1.5.1",
"babel-plugin-transform-vue-jsx": "^3.7.0",
... ... @@ -95,6 +92,7 @@
"html-webpack-plugin": "^3.2.0",
"husky": "^1.2.0",
"ignore-loader": "^0.1.2",
"lodash-webpack-plugin": "^0.11.5",
"memory-fs": "^0.4.1",
"mini-css-extract-plugin": "^0.5.0",
"node-sass": "^4.11.0",
... ...
... ... @@ -128,7 +128,7 @@
dependencies:
"@babel/types" "^7.0.0"
"@babel/helper-module-imports@^7.0.0":
"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.0.0-beta.49":
version "7.0.0"
resolved "http://npm.yohops.com/@babel%2fhelper-module-imports/-/helper-module-imports-7.0.0.tgz#96081b7111e486da4d2cd971ad1a4fe216cc2e3d"
dependencies:
... ... @@ -613,6 +613,15 @@
lodash "^4.17.10"
to-fast-properties "^2.0.0"
"@babel/types@^7.0.0-beta.49":
version "7.5.5"
resolved "http://npm.yohops.com/@babel%2ftypes/-/types-7.5.5.tgz#97b9f728e182785909aa4ab56264f090a028d18a"
integrity sha1-l7n3KOGCeFkJqkq1YmTwkKAo0Yo=
dependencies:
esutils "^2.0.2"
lodash "^4.17.13"
to-fast-properties "^2.0.0"
"@babel/types@^7.2.2":
version "7.2.2"
resolved "http://npm.yohops.com/@babel%2ftypes/-/types-7.2.2.tgz#44e10fc24e33af524488b716cdaee5360ea8ed1e"
... ... @@ -1075,6 +1084,17 @@ babel-plugin-import@^1.11.0:
"@babel/helper-module-imports" "^7.0.0"
"@babel/runtime" "^7.0.0"
babel-plugin-lodash@^3.3.4:
version "3.3.4"
resolved "http://npm.yohops.com/babel-plugin-lodash/-/babel-plugin-lodash-3.3.4.tgz#4f6844358a1340baed182adbeffa8df9967bc196"
integrity sha1-T2hENYoTQLrtGCrb7/qN+ZZ7wZY=
dependencies:
"@babel/helper-module-imports" "^7.0.0-beta.49"
"@babel/types" "^7.0.0-beta.49"
glob "^7.1.1"
lodash "^4.17.10"
require-package-name "^2.0.1"
babel-plugin-syntax-jsx@^6.18.0:
version "6.18.0"
resolved "http://npm.yohops.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"
... ... @@ -3181,6 +3201,18 @@ glob@^7.0.5:
once "^1.3.0"
path-is-absolute "^1.0.0"
glob@^7.1.1:
version "7.1.4"
resolved "http://npm.yohops.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255"
integrity sha1-qmCKL2xXetNX4a5aXCbZqNGWklU=
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.4"
once "^1.3.0"
path-is-absolute "^1.0.0"
global-dirs@^0.1.0:
version "0.1.1"
resolved "http://npm.yohops.com/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445"
... ... @@ -4287,6 +4319,13 @@ locate-path@^3.0.0:
p-locate "^3.0.0"
path-exists "^3.0.0"
lodash-webpack-plugin@^0.11.5:
version "0.11.5"
resolved "http://npm.yohops.com/lodash-webpack-plugin/-/lodash-webpack-plugin-0.11.5.tgz#c4bd064b4f561c3f823fa5982bdeb12c475390b9"
integrity sha1-xL0GS09WHD+CP6WYK96xLEdTkLk=
dependencies:
lodash "^4.17.4"
lodash._baseclone@~4.5.0:
version "4.5.7"
resolved "http://npm.yohops.com/lodash._baseclone/-/lodash._baseclone-4.5.7.tgz#ce42ade08384ef5d62fa77c30f61a46e686f8434"
... ... @@ -4362,6 +4401,11 @@ lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.3,
version "4.17.11"
resolved "http://npm.yohops.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
lodash@^4.17.13:
version "4.17.15"
resolved "http://npm.yohops.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg=
log-symbols@^2.0.0:
version "2.2.0"
resolved "http://npm.yohops.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a"
... ... @@ -6154,6 +6198,11 @@ require-main-filename@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1"
require-package-name@^2.0.1:
version "2.0.1"
resolved "http://npm.yohops.com/require-package-name/-/require-package-name-2.0.1.tgz#c11e97276b65b8e2923f75dabf5fb2ef0c3841b9"
integrity sha1-wR6XJ2tluOKSP3Xav1+y7ww4Qbk=
require-uncached@^1.0.3:
version "1.0.3"
resolved "http://npm.yohops.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3"
... ...