Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
feat: add commonjs output.
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Apr 6, 2019
1 parent ce53680 commit 8349077
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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 ..",
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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--- --- --- --- ---');
Expand Down
75 changes: 75 additions & 0 deletions webpack.config.common.js
Original file line number Diff line number Diff line change
@@ -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,
},
}],
},
]
},
}}

0 comments on commit 8349077

Please sign in to comment.