This commit is contained in:
Gus Caplan
2017-10-25 16:09:36 -05:00
parent 0589b7d7f1
commit f8f804da36
4 changed files with 53 additions and 63 deletions

View File

@@ -14,8 +14,6 @@ deploy/
.vscode/ .vscode/
docs/ docs/
webpack/
# NPM ignore # NPM ignore
.eslintrc.json .eslintrc.json
.gitattributes .gitattributes

View File

@@ -10,7 +10,8 @@
"docs:test": "docgen --source src --custom docs/index.yml --jsdoc jsdoc.json", "docs:test": "docgen --source src --custom docs/index.yml --jsdoc jsdoc.json",
"lint": "eslint src *.js", "lint": "eslint src *.js",
"lint:fix": "eslint --fix src", "lint:fix": "eslint --fix src",
"webpack": "parallel-webpack" "build:browser": "webpack",
"prepublishOnly": "npm run test && npm run build:browser"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -31,6 +32,7 @@
}, },
"homepage": "https://github.com/hydrabolt/discord.js#readme", "homepage": "https://github.com/hydrabolt/discord.js#readme",
"runkitExampleFilename": "./docs/examples/ping.js", "runkitExampleFilename": "./docs/examples/ping.js",
"unpkg": "./webpack/discord.min.js",
"dependencies": { "dependencies": {
"long": "^3.0.0", "long": "^3.0.0",
"pako": "^1.0.0", "pako": "^1.0.0",
@@ -55,7 +57,6 @@
"eslint": "^4.0.0", "eslint": "^4.0.0",
"jsdoc-strip-async-await": "^0.1.0", "jsdoc-strip-async-await": "^0.1.0",
"json-filter-loader": "^1.0.0", "json-filter-loader": "^1.0.0",
"parallel-webpack": "^2.0.0",
"uglifyjs-webpack-plugin": "^1.0.0-beta.2", "uglifyjs-webpack-plugin": "^1.0.0-beta.2",
"webpack": "^3.0.0" "webpack": "^3.0.0"
}, },

View File

@@ -32,7 +32,7 @@ fi
# Run the build # Run the build
npm run docs npm run docs
VERSIONED=false npm run webpack NODE_ENV=production npm run webpack
if [ $DONT_COMMIT == true ]; then if [ $DONT_COMMIT == true ]; then
echo -e "\e[36m\e[1mNot commiting - exiting early" echo -e "\e[36m\e[1mNot commiting - exiting early"
@@ -78,7 +78,6 @@ TARGET_BRANCH="webpack"
git clone $REPO out -b $TARGET_BRANCH git clone $REPO out -b $TARGET_BRANCH
# Move the generated webpack over # Move the generated webpack over
mv webpack/discord.js out/discord.$SOURCE.js
mv webpack/discord.min.js out/discord.$SOURCE.min.js mv webpack/discord.min.js out/discord.$SOURCE.min.js
# Commit and push # Commit and push

View File

@@ -1,38 +1,33 @@
/*
ONLY RUN BUILDS WITH `npm run webpack`!
DO NOT USE NORMAL WEBPACK! IT WILL NOT WORK!
*/
const path = require('path'); const path = require('path');
const webpack = require('webpack'); const webpack = require('webpack');
const createVariants = require('parallel-webpack').createVariants;
const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const version = require('./package.json').version; const version = require('./package.json').version;
const createConfig = options => { const plugins = [
const plugins = [
new webpack.optimize.ModuleConcatenationPlugin(), new webpack.optimize.ModuleConcatenationPlugin(),
]; ];
if (options.minify) { const prod = process.env.NODE_ENV === 'production';
if (prod) {
plugins.push(new UglifyJSPlugin({ plugins.push(new UglifyJSPlugin({
uglifyOptions: { uglifyOptions: {
mangle: { keep_classnames: true }, mangle: { keep_classnames: true },
output: { comments: false }, output: { comments: false },
}, },
})); }));
} }
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
const filename = `discord${process.env.VERSIONED === 'false' ? '' : `.${version}`}${options.minify ? '.min' : ''}.js`; const filename = `discord${process.env.VERSIONED ? `.${version}` : ''}${prod ? '.min' : ''}.js`;
return { module.exports = {
entry: './src/index.js', entry: './src/index.js',
output: { output: {
path: path.resolve('./webpack'), path: path.resolve('./webpack'),
filename, filename,
library: 'Discord', library: 'Discord',
libraryTarget: 'window', libraryTarget: 'umd',
}, },
module: { module: {
rules: [ rules: [
@@ -62,7 +57,4 @@ const createConfig = options => {
zlib: 'empty', zlib: 'empty',
}, },
plugins, plugins,
};
}; };
module.exports = createVariants({}, { minify: [false, true] }, createConfig);