diff --git a/.babelrc b/.babelrc index 071c9af..0c2e89c 100644 --- a/.babelrc +++ b/.babelrc @@ -5,7 +5,8 @@ }] ], "plugins": [ - "syntax-dynamic-import" - ] + "syntax-dynamic-import", + "lodash" + ], } diff --git a/package-lock.json b/package-lock.json index 7d1b19d..d446cd7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -155,7 +155,7 @@ "integrity": "sha512-xAfGg1/NTLBBKlHFmnd7PlmUW9KhVQIUuSrYem9xzFUZy13ScvtyGGejaae9iAVRiRq9+Cx7DPFaAAhCpyxyPw==", "dev": true, "requires": { - "lodash": "4.17.2" + "lodash": "4.17.4" } }, "async-each": { @@ -321,6 +321,35 @@ "babel-types": "6.26.0" } }, + "babel-helper-module-imports": { + "version": "7.0.0-beta.3", + "resolved": "https://registry.npmjs.org/babel-helper-module-imports/-/babel-helper-module-imports-7.0.0-beta.3.tgz", + "integrity": "sha512-bdPrIXbUTYfREhRhjbN8SstwQaj0S4+rW4PKi1f2Wc5fizSh0hGYkfXUdiSSOgyTydm956tAyz4FrG61bqdQyw==", + "dev": true, + "requires": { + "babel-types": "7.0.0-beta.3", + "lodash": "4.17.4" + }, + "dependencies": { + "babel-types": { + "version": "7.0.0-beta.3", + "resolved": "https://registry.npmjs.org/babel-types/-/babel-types-7.0.0-beta.3.tgz", + "integrity": "sha512-36k8J+byAe181OmCMawGhw+DtKO7AwexPVtsPXoMfAkjtZgoCX3bEuHWfdE5sYxRM8dojvtG/+O08M0Z/YDC6w==", + "dev": true, + "requires": { + "esutils": "2.0.2", + "lodash": "4.17.4", + "to-fast-properties": "2.0.0" + } + }, + "to-fast-properties": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", + "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", + "dev": true + } + } + }, "babel-helper-optimise-call-expression": { "version": "6.24.1", "resolved": "https://registry.npmjs.org/babel-helper-optimise-call-expression/-/babel-helper-optimise-call-expression-6.24.1.tgz", @@ -416,6 +445,19 @@ "babel-runtime": "6.26.0" } }, + "babel-plugin-lodash": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/babel-plugin-lodash/-/babel-plugin-lodash-3.3.2.tgz", + "integrity": "sha512-lNsptTRfc0FTdW56O087EiKEADVEjJo2frDQ97olMjCKbRZfZPu7MvdyxnZLOoDpuTCtavN8/4Zk65x4gT+C3Q==", + "dev": true, + "requires": { + "babel-helper-module-imports": "7.0.0-beta.3", + "babel-types": "6.26.0", + "glob": "7.1.1", + "lodash": "4.17.4", + "require-package-name": "2.0.1" + } + }, "babel-plugin-syntax-async-functions": { "version": "6.13.0", "resolved": "https://registry.npmjs.org/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz", @@ -1270,6 +1312,12 @@ "right-pad": "1.0.1", "word-wrap": "1.2.3" } + }, + "lodash": { + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.2.tgz", + "integrity": "sha1-NKMFW6vgTOQkZ7YH1wAHLH/2v0I=", + "dev": true } } }, @@ -2348,7 +2396,7 @@ "cli-width": "2.2.0", "external-editor": "1.1.1", "figures": "1.7.0", - "lodash": "4.17.2", + "lodash": "4.17.4", "mute-stream": "0.0.6", "pinkie-promise": "2.0.1", "run-async": "2.3.0", @@ -2673,11 +2721,20 @@ } }, "lodash": { - "version": "4.17.2", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.2.tgz", - "integrity": "sha1-NKMFW6vgTOQkZ7YH1wAHLH/2v0I=", + "version": "4.17.4", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", + "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=", "dev": true }, + "lodash-webpack-plugin": { + "version": "0.11.4", + "resolved": "https://registry.npmjs.org/lodash-webpack-plugin/-/lodash-webpack-plugin-0.11.4.tgz", + "integrity": "sha1-bD7Lo9S40ktTlAtjVCcVxe08SsU=", + "dev": true, + "requires": { + "lodash": "4.17.4" + } + }, "lodash.map": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/lodash.map/-/lodash.map-4.6.0.tgz", @@ -3619,6 +3676,12 @@ "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=", "dev": true }, + "require-package-name": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/require-package-name/-/require-package-name-2.0.1.tgz", + "integrity": "sha1-wR6XJ2tluOKSP3Xav1+y7ww4Qbk=", + "dev": true + }, "resolve": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.5.0.tgz", @@ -4256,7 +4319,7 @@ "dev": true, "requires": { "fs-extra": "0.30.0", - "lodash": "4.17.2" + "lodash": "4.17.4" }, "dependencies": { "fs-extra": { diff --git a/package.json b/package.json index efe824d..979c02f 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,15 @@ "devDependencies": { "babel-core": "^6.26.0", "babel-loader": "^7.1.2", + "babel-plugin-lodash": "^3.3.2", "babel-plugin-syntax-dynamic-import": "^6.18.0", "babel-preset-env": "^1.6.1", "commitizen": "^2.9.6", "current-device": "^0.7.2", "cz-conventional-changelog": "^2.1.0", "html-loader": "^0.5.1", + "lodash": "^4.17.4", + "lodash-webpack-plugin": "^0.11.4", "path": "^0.12.7", "uglifyjs-webpack-plugin": "^1.1.5", "webpack": "^3.10.0", diff --git a/src/cLive2DApp.js b/src/cLive2DApp.js index 3c0cb96..aaf7d4b 100644 --- a/src/cLive2DApp.js +++ b/src/cLive2DApp.js @@ -41,7 +41,6 @@ let opacityDefault = 0.7; let opacityHover = 1; export default () => { - console.log(config); /* headPos = typeof iHeadPos === 'undefined' ? 0.5 : iHeadPos; opacityDefault = typeof iOpacityDefault === 'undefined' ? 0.7 : iOpacityDefault; diff --git a/src/configValidater.js b/src/configValidater.js new file mode 100644 index 0000000..e69de29 diff --git a/src/index.js b/src/index.js index 8012238..2a8010c 100644 --- a/src/index.js +++ b/src/index.js @@ -13,7 +13,7 @@ 'use strict'; import device from 'current-device'; -import { config, applyConfig }from './lib/configManager.js'; +import { config, configApplyer }from './lib/configManager.js'; /** * The public entry point @@ -22,19 +22,21 @@ import { config, applyConfig }from './lib/configManager.js'; export function init(userConfig){ + userConfig = typeof userConfig === 'undefined' ? {} : userConfig; + if (process.env.NODE_ENV === 'development') { console.log('Hey that, you are now in DEV MODE.'); } try{ - applyConfig(userConfig); + configApplyer(userConfig); }catch(err){ console.error(err); } - +/* if((!config.mobile.show)&&(device.mobile())){ return; } - +*/ import(/* webpackMode: "lazy" */ './cLive2DApp').then(_ => { _.default(); }).catch(err => { diff --git a/src/lib/configManager.js b/src/lib/configManager.js index 1e6b7bc..4e91698 100644 --- a/src/lib/configManager.js +++ b/src/lib/configManager.js @@ -4,6 +4,7 @@ * @description The container of configeration. */ +import _ from 'lodash'; let currConfig = {}; @@ -46,7 +47,8 @@ const defaultOptions = { checked: true, } -function applyConfig(inUserConfig){ +function configApplyer(inUserConfig){ + console.log(_.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 })); if (!!!inUserConfig.checked) checkUserConfig(inUserConfig); // TBD. } @@ -54,7 +56,12 @@ function applyConfig(inUserConfig){ function checkUserConfig(inUserConfig){ // TBD. } + +function configDefaulter(){ + +} + export { - applyConfig, + configApplyer, currConfig as config, } diff --git a/webpack.config.js b/webpack.config.js index fc97d11..dc8c958 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,6 @@ const webpack = require('webpack'); -const path = require('path') +const path = require('path'); +const LodashModuleReplacementPlugin = require('lodash-webpack-plugin'); const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); const visualizer = require('webpack-visualizer-plugin'); const manifestPlugin = require('webpack-manifest-plugin'); @@ -36,6 +37,7 @@ module.exports = env => {return{ 'NODE_ENV': JSON.stringify((isProd(env) ? 'production' : 'development')), } }), + new LodashModuleReplacementPlugin(), new UglifyJsPlugin({ cache: false, parallel: true,