-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from dmvt/reduce-driver-to-less-than-1-MB
reduces development driver size to ~683k by removing vendor sourceMaps
- Loading branch information
Showing
7 changed files
with
179 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const { ConcatSource } = require('webpack-sources') | ||
|
||
module.exports = class AddVendorsPlugin { | ||
constructor(base) { | ||
this.base = base | ||
} | ||
|
||
apply(compiler) { | ||
compiler.hooks.emit.tapAsync( | ||
`AddVendorsPlugin ${this.base}`, | ||
(compilation, callback) => { | ||
const main = compilation.assets[`main.${this.base}`] | ||
const mainMap = compilation.assets[`main.${this.base}.map`] | ||
const vendor = compilation.assets[`vendors.${this.base}`] | ||
|
||
if (main && vendor) { | ||
const compiledAsset = new ConcatSource(main.children[0]) | ||
compiledAsset.add(vendor) | ||
compiledAsset.add(main.children[1]) | ||
compilation.assets = {} | ||
compilation.assets[this.base] = compiledAsset | ||
} else if (main && mainMap) { | ||
compilation.assets = {} | ||
compilation.assets[this.base] = main | ||
compilation.assets[`${this.base}.map`] = mainMap | ||
} | ||
callback() | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-disable strict, no-console, object-shorthand */ | ||
|
||
'use strict' | ||
|
||
const { paths } = require('./webpack.parts.js') | ||
|
||
module.exports = { | ||
entry: paths.entry, | ||
mode: 'none', | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: 'babel-loader', | ||
}, | ||
} | ||
] | ||
}, | ||
optimization: { | ||
minimize: true, | ||
noEmitOnErrors: true | ||
}, | ||
resolve: { | ||
extensions: ['.js'], | ||
modules: ['node_modules'], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable strict, no-console, object-shorthand */ | ||
|
||
'use strict' | ||
|
||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin') | ||
|
||
module.exports = { | ||
devtool: 'inline-source-map', | ||
optimization: { | ||
minimizer: [ | ||
new UglifyJsPlugin({ | ||
test: /vendor/, | ||
sourceMap: false, | ||
}), | ||
new UglifyJsPlugin({ | ||
test: /^((?!(vendor)).)*.js$/, | ||
sourceMap: true, | ||
}) | ||
], | ||
splitChunks: { | ||
cacheGroups: { | ||
commons: { | ||
test: /[\\/]node_modules[\\/]/, | ||
name: 'vendors', | ||
chunks: 'all' | ||
} | ||
} | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* eslint-disable strict, no-console, object-shorthand */ | ||
|
||
'use strict' | ||
|
||
const path = require('path') | ||
const merge = require('webpack-merge') | ||
|
||
const development = require('./webpack.development.js') | ||
const production = require('./webpack.production.js') | ||
|
||
const AddVendorsPlugin = require('./plugins/add-vendors-plugin') | ||
|
||
const paths = { | ||
entry: path.resolve(__dirname, './src/index.js'), | ||
bundle: path.resolve(__dirname, 'dist/browser'), | ||
} | ||
|
||
const outputs = (base, env, mapping, overrides) => { | ||
const collection = [] | ||
const library = 'bigchaindb-driver' | ||
const windowLibrary = 'BigchainDB' | ||
|
||
let environment = development | ||
let ext = 'js' | ||
|
||
if (env === 'production') { | ||
environment = production | ||
ext = `min.${ext}` | ||
} | ||
|
||
Object.entries(mapping).forEach(([target, extension]) => { | ||
const filename = `[name].${library}.${extension}.${ext}` | ||
|
||
const compiled = { | ||
output: { | ||
filename: filename, | ||
library: target === 'window' ? windowLibrary : library, | ||
libraryTarget: target, | ||
path: paths.bundle | ||
}, | ||
plugins: [ | ||
new AddVendorsPlugin(`${library}.${extension}.${ext}`) | ||
] | ||
} | ||
|
||
collection.push(merge(base, environment, compiled, overrides)) | ||
}) | ||
|
||
return collection | ||
} | ||
|
||
module.exports = { | ||
outputs, | ||
paths | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* eslint-disable strict, no-console, object-shorthand */ | ||
|
||
'use strict' | ||
|
||
module.exports = { | ||
devtool: 'source-map', | ||
} |