Skip to content

Commit

Permalink
Reduce build size for voyager lib (vega#678)
Browse files Browse the repository at this point in the history
* Modifies webpack config lib to mark certain libraries as external + adds webpack config for electron build

* Modifies npm scripts to generate lib and electron voyager builds + fixes test script based on addition of external to webpack lib config

* Adds back source maps

* Removes electron webpack build as voyager built as library should be enough for electron environments

* Adds back sources-map-loader in webpack.config.lib.js
  • Loading branch information
ajainarayanan authored and kanitw committed Sep 1, 2017
1 parent 4c5a341 commit 64ef9d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
28 changes: 25 additions & 3 deletions config/webpack.config.lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ module.exports = {
{ test: /\.tsx?$/, use: "ts-loader" },
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ test: /\.js$/, use: "source-map-loader", enforce: "pre" },

{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
Expand Down Expand Up @@ -108,14 +107,37 @@ module.exports = {
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
externals: {
// "react": "React",
// "react-dom": "ReactDOM"
"react": "react",
"react-dom": "react-dom",
"react-css-modules": 'react-css-modules',
"react-dnd": "react-dnd",
"react-dnd-html5-backend": "react-dnd-html5-backend",
"react-redux": "react-redux",
"react-tether": "react-tether",
"redux": "redux",
"redux-thunk": "redux-thunk",
"redux-undo": "redux-undo",
"vega": "vega",
"vega-lite": "vega-lite",
"vega-tooltip": "vega-tooltip",
"moment": "moment",
"font-awesome": "font-awesome",
"font-awesome-sass-loader": "font-awesome-sass-loader"
},
plugins: [
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
new webpack.DefinePlugin(env.stringified),

new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
output: {
comments: false,
},
sourceMap: true,
}),
// Watcher doesn't work well if you mistype casing in a path so we use
// a plugin that prints an error when you attempt to do this.
// See https://github.com/facebookincubator/create-react-app/issues/240
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"start:server": "cross-env SERVER=\"http://localhost:3000\" webpack-dev-server --open --config config/webpack.config.dev.js",
"build": "node scripts/build.js",
"postbuild": "npm run tsc && npm run build:lib",
"build:lib": "webpack -d --config config/webpack.config.lib.js",
"build:lib": "webpack --config config/webpack.config.lib.js",
"watch": "webpack -d --watch",
"clean": "find -E dist -regex '.*\\.(js|js.map|d.ts)' -delete",
"lint": "tslint -c tslint.json 'src/**/*.ts' 'src/**/*.tsx'",
Expand Down
2 changes: 1 addition & 1 deletion scripts/jest-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const glob = require('glob');
config.output.publicPath = '/lib-test/';
config.output.path = path.resolve(__dirname, '../lib-test');
config.output.filename = '[name].js';
config.externals = {};


const basedir = path.resolve(__dirname, '../src');
Expand All @@ -30,7 +31,6 @@ config.entry = tests
return carry;
}, {});


const compiler = webpack(config);
compiler.run(function() {});

Expand Down

0 comments on commit 64ef9d1

Please sign in to comment.