From 8349077678655ec40af5a8cbb5019f77a5f195fe Mon Sep 17 00:00:00 2001 From: eyhn Date: Sat, 6 Apr 2019 09:39:23 +0800 Subject: [PATCH] feat: add commonjs output. --- package.json | 5 +-- src/index.js | 1 - webpack.config.common.js | 75 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 webpack.config.common.js diff --git a/package.json b/package.json index 95ed430..932630b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "live2d-widget", "version": "3.1.3", - "main": "./lib/L2Dwidget.min.js", + "main": "./lib/L2Dwidget.common.js", "description": "Add the Sseexxyyy live2d to webpages.", "scripts": { "update:submodule": "git submodule foreach git pull origin master", @@ -10,7 +10,8 @@ "_titlechangelog": "sed -i '1i\\# Changelog\\n\\n' CHANGELOG.md", "inst:dev": "npm install -g commitizen && npm install -g conventional-changelog-cli && npm install", "build:dev": "./node_modules/.bin/webpack --progress --colors", - "build:prod": "./node_modules/.bin/webpack --env prod --progress --colors", + "build:prod": "./node_modules/.bin/webpack --env prod --progress --colors && npm run build:module", + "build:module": "./node_modules/.bin/webpack --env prod --progress --colors --config webpack.config.common.js", "build:docs": "git pull && npm run _changelog && git add CHANGELOG.md && npm run update:submodule && git add ghpages", "build:esdoc": "cp lib/stats.html ghpages/stats.html -f && npm run _titlechangelog && npm run _esdoc", "deploy:doc": "git pull && git checkout master && cd ghpages/ && git status && git add --all && git commit -m \"Update docs\" && git push origin HEAD:master --force && cd ..", diff --git a/src/index.js b/src/index.js index 97af679..92de74e 100644 --- a/src/index.js +++ b/src/index.js @@ -13,7 +13,6 @@ import device from 'current-device'; import { config, configApplyer }from './config/configMgr'; -import live2dWidgetDialog from './dialog'; if (process.env.NODE_ENV === 'development'){ console.log('--- --- --- --- ---\nLive2Dwidget: Hey that, notice that you are now in DEV MODE.\n--- --- --- --- ---'); diff --git a/webpack.config.common.js b/webpack.config.common.js new file mode 100644 index 0000000..f6860e4 --- /dev/null +++ b/webpack.config.common.js @@ -0,0 +1,75 @@ +const webpack = require('webpack'); +const path = require('path'); +const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); +const nowDate = new Date(); +const isProd = e => e === 'prod'; + +module.exports = env => {return{ + + entry: [ + './src/index.js', + ], + + output: { + filename: 'L2Dwidget.common.js', + libraryTarget: 'commonjs', + path: path.resolve(__dirname, 'lib'), + pathinfo: (isProd(env) ? false : true), + }, + + target: 'node', + + devtool: 'source-map', + + watch: (isProd(env) ? false : true), + + plugins: [ + new webpack.DefinePlugin({ + 'process.env': { + 'NODE_ENV': JSON.stringify((isProd(env) ? 'production' : 'development')), + }, + }), + new UglifyJsPlugin({ + cache: false, + parallel: true, + sourceMap: true, + uglifyOptions: { + // The L2D core library was droped too much, + // so the warnings is useless recently. + warnings: false, + mangle: true, + compress: { + drop_console: false, + }, + }, + }), + new webpack.optimize.LimitChunkCountPlugin({ + maxChunks: 1, + }), + // Banner must be put below UglifyJsPlugin, or it won't work. + new webpack.BannerPlugin(`${isProd(env) ? '' : '___DEV___'}https://github.com/xiazeyu/live2d-widget.js built@${nowDate.toLocaleDateString()} ${nowDate.toLocaleTimeString()}`), + ], + + resolve: { + extensions: ['.js','.html', '.webpack.js', '.web.js'], + }, + + module: { + rules: [ + {test: /\.js$/, + include: path.resolve(__dirname, "src"), + use: [{ + loader: 'babel-loader', + }], + }, + {test: /\.html$/, + use: [{ + loader: 'html-loader', + options: { + minimize: true, + }, + }], + }, + ] + }, +}}