Skip to content

Commit

Permalink
feat: use uglifyjs-webpack-plugin instead of babel-minify
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Feb 20, 2018
1 parent 1aa3d47 commit 10ce01d
Show file tree
Hide file tree
Showing 9 changed files with 798 additions and 700 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@
"devDependencies": {
"@develar/gitbook": "3.2.11",
"@types/electron-devtools-installer": "^2.0.2",
"@types/jest": "^22.0.1",
"@types/jest": "^22.1.3",
"@types/memory-fs": "^0.3.0",
"@types/node": "9.3.0",
"@types/semver": "^5.4.0",
"@types/webpack": "^3.8.3",
"@types/node": "9.4.6",
"@types/semver": "^5.5.0",
"@types/webpack": "^3.8.8",
"babel-preset-ts-node6-bluebird": "^1.0.1",
"develar-typescript-json-schema": "^0.19.0",
"develar-typescript-json-schema": "^0.20.0",
"electron-builder-tslint-config": "^1.1.0",
"fs-extra-p": "^4.5.0",
"fs-extra-p": "^4.5.2",
"gitbook-plugin-analytics": "^0.2.1",
"gitbook-plugin-edit-link": "^2.0.2",
"gitbook-plugin-github": "^3.0.0",
"gitbook-plugin-github-buttons": "^3.0.0",
"http-server": "^0.11.1",
"jest-cli": "^22.1.4",
"jest-junit": "^3.4.1",
"jest-cli": "^22.3.0",
"jest-junit": "^3.6.0",
"memory-fs": "^0.4.1",
"temp-file": "^3.1.1",
"ts-babel": "^4.1.8",
"tslint": "^5.9.1",
"typescript": "^2.6.2",
"webpack": "^3.10.0"
"typescript": "^2.7.2",
"webpack": "^3.11.0"
},
"babel": {
"presets": [
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-webpack-eslint/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "electron-webpack-eslint",
"version": "1.3.0",
"version": "1.3.1",
"license": "MIT",
"author": "Greg Holguin <[email protected]>",
"files": [],
"repository": "electron-userland/electron-webpack",
"dependencies": {
"babel-eslint": "^8.2.1",
"eslint": "^4.16.0",
"eslint": "^4.18.0",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.9.0"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/electron-webpack-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "electron-webpack-ts",
"version": "1.3.0",
"version": "1.4.0",
"license": "MIT",
"author": "Vladimir Krivosheev <[email protected]>",
"files": [],
"repository": "electron-userland/electron-webpack",
"dependencies": {
"fork-ts-checker-webpack-plugin": "^0.3.0",
"ts-loader": "^3.3.1"
"ts-loader": "^3.5.0"
},
"peerDependencies": {
"typescript": "^2.4.1"
"typescript": "^2.7.2"
}
}
8 changes: 4 additions & 4 deletions packages/electron-webpack-vue/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "electron-webpack-vue",
"version": "1.3.0",
"version": "1.4.0",
"license": "MIT",
"author": "Vladimir Krivosheev <[email protected]>",
"files": [],
"repository": "electron-userland/electron-webpack",
"dependencies": {
"vue-class-component": "^6.1.2",
"vue-class-component": "^6.2.0",
"vue-html-loader": "^1.2.4",
"vue-loader": "^13.7.0",
"vue-style-loader": "^3.1.1",
"vue-loader": "^14.1.1",
"vue-style-loader": "^4.0.2",
"vue-template-compiler": "^2.5.13"
}
}
22 changes: 11 additions & 11 deletions packages/electron-webpack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-webpack",
"version": "1.12.1",
"version": "1.13.0",
"license": "MIT",
"author": "Vladimir Krivosheev <[email protected]>",
"main": "out/main.js",
Expand All @@ -21,39 +21,39 @@
},
"//": "@types/webpack-env in the dependencies because used by clients",
"dependencies": {
"@types/webpack-env": "^1.13.4",
"@types/webpack-env": "^1.13.5",
"async-exit-hook": "^2.0.1",
"babel-minify-webpack-plugin": "^0.2.0",
"uglifyjs-webpack-plugin": "^1.2.0",
"bluebird-lst": "^1.0.5",
"chalk": "^2.3.0",
"chalk": "^2.3.1",
"crocket": "^0.9.11",
"css-hot-loader": "^1.3.6",
"css-hot-loader": "^1.3.7",
"css-loader": "^0.28.9",
"debug": "^3.1.0",
"electron-devtools-installer": "^2.2.3",
"electron-webpack-js": "~1.2.0",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.6",
"fs-extra-p": "^4.5.0",
"file-loader": "^1.1.7",
"fs-extra-p": "^4.5.2",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^2.30.1",
"lazy-val": "^1.0.3",
"node-loader": "^0.6.0",
"read-config-file": "^2.1.1",
"read-config-file": "^3.0.0",
"semver": "^5.5.0",
"source-map-support": "^0.5.3",
"style-loader": "^0.20.1",
"style-loader": "^0.20.2",
"url-loader": "^0.6.2",
"virtual-module-webpack-plugin": "^0.3.0",
"webpack-dev-server": "^2.11.1",
"webpack-merge": "^4.1.1",
"yargs": "^11.0.0"
},
"devDependencies": {
"@types/webpack-merge": "^4.1.1"
"@types/webpack-merge": "^4.1.2"
},
"peerDependencies": {
"webpack": "^3.6.0"
"webpack": "^3.11.0"
},
"types": "./out/main.d.ts",
"publishConfig": {
Expand Down
31 changes: 22 additions & 9 deletions packages/electron-webpack/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,28 @@ export { ElectronWebpackConfiguration } from "./core"

const _debug = require("debug")

// noinspection JSUnusedGlobalSymbols
export function getAppConfiguration(env: ConfigurationEnv) {
return BluebirdPromise.filter([configure("main", env), configure("renderer", env)], it => it != null)
}

// noinspection JSUnusedGlobalSymbols
export function getMainConfiguration(env: ConfigurationEnv) {
return configure("main", env)
}

// noinspection JSUnusedGlobalSymbols
export function getRendererConfiguration(env: ConfigurationEnv) {
return configure("renderer", env)
}

// in the future, if need, isRenderer = true arg can be added
// noinspection JSUnusedGlobalSymbols
export function getDllConfiguration(env: ConfigurationEnv) {
return configure("renderer-dll", env)
}

// noinspection JSUnusedGlobalSymbols
export async function getTestConfiguration(env: ConfigurationEnv) {
const configurator = await createConfigurator("test", env)
return await configurator.configure({
Expand All @@ -57,15 +62,23 @@ export class WebpackConfigurator {

readonly debug = _debug(`electron-webpack:${this.type}`)

config: Configuration
private _configuration: Configuration | null = null

get config(): Configuration {
return this._configuration!!
}

readonly rules: Array<Rule> = []
readonly plugins: Array<Plugin> = []

// js must be first - e.g. iview has two files loading-bar.js and loading-bar.vue - when we require "loading-bar", js file must be resolved and not vue
readonly extensions: Array<string> = [".js", ".json", ".node"]

electronVersion: string
private _electronVersion: string | null = null

get electronVersion(): string {
return this._electronVersion!!
}

readonly entryFiles: Array<string> = []

Expand Down Expand Up @@ -152,7 +165,7 @@ export class WebpackConfigurator {
}

async configure(entry?: { [key: string]: any } | null) {
this.config = {
this._configuration = {
context: this.projectDir,
devtool: this.isProduction || this.isTest ? "nosources-source-map" : "eval-source-map",
externals: this.computeExternals(),
Expand Down Expand Up @@ -181,11 +194,11 @@ export class WebpackConfigurator {
}

if (entry != null) {
this.config.entry = entry
this._configuration.entry = entry
}

// if electronVersion not specified, use latest
this.electronVersion = this.electronWebpackConfiguration.electronVersion || await this.electronVersionPromise.value || "1.7.5"
this._electronVersion = this.electronWebpackConfiguration.electronVersion || await this.electronVersionPromise.value || "1.8.2"
const target = (() => {
switch (this.type) {
case "renderer": return new RendererTarget()
Expand All @@ -201,7 +214,7 @@ export class WebpackConfigurator {
configureVue(this)

if (this.debug.enabled) {
this.debug(`\n\n${this.type} config:` + JSON.stringify(this.config, null, 2) + "\n\n")
this.debug(`\n\n${this.type} config:` + JSON.stringify(this._configuration, null, 2) + "\n\n")
}

if (this.config.entry == null) {
Expand Down Expand Up @@ -235,15 +248,15 @@ export class WebpackConfigurator {

private applyCustomModifications() {
if (this.type === "renderer" && this.electronWebpackConfiguration.renderer && this.electronWebpackConfiguration.renderer.webpackConfig) {
this.config = merge.smart(this.config, require(path.join(this.projectDir, this.electronWebpackConfiguration.renderer.webpackConfig)))
this._configuration = merge.smart(this._configuration!!, require(path.join(this.projectDir, this.electronWebpackConfiguration.renderer.webpackConfig)))
}

if (this.type === "renderer-dll" && this.electronWebpackConfiguration.renderer && this.electronWebpackConfiguration.renderer.webpackDllConfig) {
this.config = merge.smart(this.config, require(path.join(this.projectDir, this.electronWebpackConfiguration.renderer.webpackDllConfig)))
this._configuration = merge.smart(this._configuration!!, require(path.join(this.projectDir, this.electronWebpackConfiguration.renderer.webpackDllConfig)))
}

if (this.type === "main" && this.electronWebpackConfiguration.main && this.electronWebpackConfiguration.main.webpackConfig) {
this.config = merge.smart(this.config, require(path.join(this.projectDir, this.electronWebpackConfiguration.main.webpackConfig)))
this._configuration = merge.smart(this._configuration!!, require(path.join(this.projectDir, this.electronWebpackConfiguration.main.webpackConfig)))
}
}

Expand Down
12 changes: 9 additions & 3 deletions packages/electron-webpack/src/targets/BaseTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ export class BaseTarget {

if (configurator.isProduction) {
if (configurator.env.minify !== false) {
const BabiliWebpackPlugin = require("babel-minify-webpack-plugin")
plugins.push(new BabiliWebpackPlugin({
removeDebugger: true
const UglifyJsPlugin = require("uglifyjs-webpack-plugin")
plugins.push(new UglifyJsPlugin({
parallel: true,
sourceMap: true,
uglifyOptions: {
compress: {
ecma: 7,
},
},
}))
}
plugins.push(new DefinePlugin({
Expand Down
Loading

0 comments on commit 10ce01d

Please sign in to comment.