Merge branch 'devsnek-refactor/webpacks'

This commit is contained in:
iCrawl
2018-02-16 09:52:27 +01:00
4 changed files with 52 additions and 62 deletions

View File

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

View File

@@ -10,7 +10,8 @@
"docs:test": "docgen --source src --custom docs/index.yml",
"lint": "eslint src *.js",
"lint:fix": "eslint --fix src",
"webpack": "parallel-webpack"
"build:browser": "webpack",
"prepublishOnly": "npm run test && NODE_ENV=production npm run build:browser"
},
"repository": {
"type": "git",
@@ -31,6 +32,7 @@
},
"homepage": "https://github.com/discordjs/discord.js#readme",
"runkitExampleFilename": "./docs/examples/ping.js",
"unpkg": "./webpack/discord.min.js",
"dependencies": {
"pako": "^1.0.0",
"prism-media": "hydrabolt/prism-media",
@@ -51,7 +53,6 @@
"discord.js-docgen": "discordjs/docgen",
"eslint": "^4.17.0",
"json-filter-loader": "^1.0.0",
"parallel-webpack": "^2.2.0",
"uglifyjs-webpack-plugin": "^1.1.8",
"webpack": "^3.11.0"
},

View File

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

View File

@@ -1,67 +1,59 @@
/*
ONLY RUN BUILDS WITH `npm run webpack`!
DO NOT USE NORMAL WEBPACK! IT WILL NOT WORK!
*/
const path = require('path');
const webpack = require('webpack');
const createVariants = require('parallel-webpack').createVariants;
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const version = require('./package.json').version;
const createConfig = options => {
const plugins = [
new webpack.optimize.ModuleConcatenationPlugin(),
];
const plugins = [
new webpack.optimize.ModuleConcatenationPlugin(),
];
if (options.minify) {
plugins.push(new UglifyJSPlugin({
uglifyOptions: {
mangle: { keep_classnames: true },
output: { comments: false },
},
}));
}
const prod = process.env.NODE_ENV === 'production';
// eslint-disable-next-line max-len
const filename = `discord${process.env.VERSIONED === 'false' ? '' : `.${version}`}${options.minify ? '.min' : ''}.js`;
return {
entry: './src/index.js',
output: {
path: path.resolve('./webpack'),
filename,
library: 'Discord',
libraryTarget: 'window',
if (prod) {
plugins.push(new UglifyJSPlugin({
uglifyOptions: {
mangle: { keep_classnames: true },
output: { comments: false },
},
module: {
rules: [
{ test: /\.md$/, loader: 'ignore-loader' },
{
test: require.resolve('./package.json'),
use: {
loader: 'json-filter-loader',
options: {
used: ['version', 'homepage'],
},
}));
}
// eslint-disable-next-line max-len
const filename = `discord${process.env.VERSIONED ? `.${version}` : ''}${prod ? '.min' : ''}.js`;
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve('./webpack'),
filename,
library: 'Discord',
libraryTarget: 'umd',
},
module: {
rules: [
{ test: /\.md$/, loader: 'ignore-loader' },
{
test: require.resolve('./package.json'),
use: {
loader: 'json-filter-loader',
options: {
used: ['version', 'homepage'],
},
},
],
},
node: {
fs: 'empty',
dns: 'mock',
tls: 'mock',
child_process: 'empty',
dgram: 'empty',
__dirname: true,
process: false,
path: 'empty',
Buffer: false,
zlib: 'empty',
},
plugins,
};
},
],
},
node: {
fs: 'empty',
dns: 'mock',
tls: 'mock',
child_process: 'empty',
dgram: 'empty',
__dirname: true,
process: false,
path: 'empty',
Buffer: false,
zlib: 'empty',
},
plugins,
};
module.exports = createVariants({}, { minify: [false, true] }, createConfig);