Last active
February 1, 2016 12:44
-
-
Save Globegitter/82f57155decbe1df6073 to your computer and use it in GitHub Desktop.
webpack2 config
This file contains hidden or 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
'use strict'; | |
/* eslint-env node*/ | |
/** | |
* Our webpack config. Call with true to enable debug mode (faster rebuilds etc.) | |
* @type {function} | |
*/ | |
const webpack = require('webpack'); | |
const argv = require('minimist')(process.argv.slice(2), { | |
'boolean': ['minify', 'src_maps'] | |
}); | |
const path = require('path'); | |
const PLZ_TEMP_DIR = 'plz-out/tmp'; | |
const ROOT_DIR = argv.root_dir || process.env.ROOT_DIR; | |
const TMP_DIR = argv.tmp_dir || process.env.TMP_DIR; | |
const PKG = argv.pkg || process.env.PKG; | |
const NAME = argv.name || process.env.NAME; | |
const PUBLIC_PATH = argv.public_path || '/js/'; | |
const RELAY_SCHEMA_PATH = argv.relay_schema_path || false; | |
// TODO(benh): support multiple entry points | |
let srcs = argv.src ? argv.src : []; | |
srcs = typeof srcs === 'string' ? [srcs] : srcs; | |
const minify = argv.minify; | |
const isNode = argv.node; | |
const output = argv.o; | |
const srcMaps = argv.src_maps; | |
const PACKAGE_ROOT = path.join(TMP_DIR, PKG); | |
const THIRD_PARTY_DIR = path.join(ROOT_DIR, PLZ_TEMP_DIR, PKG, NAME, 'third_party/js'); | |
module.exports = (inDebugMode) => { | |
const debug = inDebugMode ? true : false; | |
const plugins = []; | |
let srcMapSetting = srcMaps ? 'source-map' : false; | |
if (minify) { | |
plugins.push(new webpack.DefinePlugin({ | |
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) | |
})); | |
plugins.push(new webpack.optimize.UglifyJsPlugin()); | |
plugins.push(new webpack.optimize.DedupePlugin()); | |
} | |
if (debug) { | |
// eval-cheap-source-map are super fast and perfect for debugging | |
srcMapSetting = srcMaps ? 'eval-cheap-source-map' : false; | |
} | |
const entry = [ | |
// The usual es6 etc. polyfills | |
require.resolve('babel-polyfill') | |
]; | |
if (!isNode) { | |
entry.push(require.resolve('whatwg-fetch')); | |
} | |
srcs.forEach(src => entry.push(path.join(PACKAGE_ROOT, src))); | |
const BABEL_PLUGIN_PATH = path.resolve('./custom_babel_plugins'); | |
const BABEL_QUERY = { | |
presets: [ | |
require.resolve('babel-preset-react') | |
], | |
plugins: [ | |
// Had issues with decorators removing statics so make sure this is run first | |
require.resolve('babel-plugin-transform-decorators-legacy'), | |
require.resolve('babel-plugin-syntax-trailing-function-commas'), | |
require.resolve('babel-plugin-transform-class-properties'), | |
require.resolve('babel-plugin-transform-object-rest-spread'), | |
require.resolve('babel-plugin-syntax-async-functions'), | |
require.resolve('babel-plugin-transform-regenerator'), | |
require.resolve('babel-plugin-transform-es2015-template-literals'), | |
require.resolve('babel-plugin-transform-es2015-literals'), | |
require.resolve('babel-plugin-transform-es2015-function-name'), | |
require.resolve('babel-plugin-transform-es2015-arrow-functions'), | |
require.resolve('babel-plugin-transform-es2015-block-scoped-functions'), | |
require.resolve('babel-plugin-transform-es2015-classes'), | |
require.resolve('babel-plugin-transform-es2015-object-super'), | |
require.resolve('babel-plugin-transform-es2015-shorthand-properties'), | |
require.resolve('babel-plugin-transform-es2015-computed-properties'), | |
require.resolve('babel-plugin-transform-es2015-for-of'), | |
require.resolve('babel-plugin-transform-es2015-sticky-regex'), | |
require.resolve('babel-plugin-transform-es2015-unicode-regex'), | |
require.resolve('babel-plugin-check-es2015-constants'), | |
require.resolve('babel-plugin-transform-es2015-spread'), | |
require.resolve('babel-plugin-transform-es2015-parameters'), | |
require.resolve('babel-plugin-transform-es2015-destructuring'), | |
require.resolve('babel-plugin-transform-es2015-block-scoping'), | |
require.resolve('babel-plugin-transform-es2015-typeof-symbol'), | |
path.resolve(BABEL_PLUGIN_PATH, 'rootPath.js') | |
], | |
sourceMaps: false | |
}; | |
if (RELAY_SCHEMA_PATH) { | |
const babelPluginPath = path.resolve(BABEL_PLUGIN_PATH, 'babelRelayPlugin.js'); | |
BABEL_QUERY.plugins.push(babelPluginPath); | |
} | |
return { | |
entry, | |
output: { | |
path: TMP_DIR, | |
sourceMapFilename:'[file].map', | |
publicPath: PUBLIC_PATH, | |
filename: output, | |
chunkFilename: '[id]-[chunkhash].js' | |
}, | |
debug, | |
watch: debug, | |
cache: debug ? {} : false, | |
// pixi uses fs for some stupid reason | |
node: {fs: 'empty'}, | |
devtool: srcMapSetting, | |
plugins, | |
// TODO (benh): Get the alias from plz build rules | |
resolve: { | |
root: THIRD_PARTY_DIR | |
}, | |
module: { | |
preLoaders: [ | |
{test: /\.json$/, exclude: /node_modules/, loader: 'json'}, | |
{test: /\.glsl$/, loader: 'shader'} | |
], | |
loaders: [ | |
// we tell webpack to ignore AMD so we don't have to write rules to replace the paths of these too | |
// As some third party libs try AMD before require | |
{ | |
test: /\.(js|jsx)?$/, | |
exclude: /(third_party|node_modules)/, | |
loader: 'babel', | |
query: BABEL_QUERY | |
}, | |
{test: /\.(js|jsx)?$/, loader: 'imports?define=>false'} | |
] | |
}, | |
resolveLoader: { | |
root: process.env.NODE_PATH | |
} | |
}; | |
}; |
This file contains hidden or 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
include_defs('//buildSrc/javascript.build_defs') | |
node_binary( | |
name='build_js', | |
src=glob(['*.js', 'src/*.js', 'custom_babel_plugins/*.js']), | |
deps=[ | |
'//third_party/js:babel-core', | |
'//third_party/js:babel-loader', | |
'//third_party/js:babel-plugin-syntax-async-functions', | |
'//third_party/js:babel-plugin-syntax-trailing-function-commas', | |
'//third_party/js:babel-plugin-transform-class-properties', | |
'//third_party/js:babel-plugin-transform-decorators', | |
'//third_party/js:babel-plugin-transform-decorators-legacy', | |
'//third_party/js:babel-plugin-transform-object-rest-spread', | |
'//third_party/js:babel-plugin-transform-regenerator', | |
'//third_party/js:babel-plugin-transform-es2015-template-literals', | |
'//third_party/js:babel-plugin-transform-es2015-literals', | |
'//third_party/js:babel-plugin-transform-es2015-function-name', | |
'//third_party/js:babel-plugin-transform-es2015-arrow-functions', | |
'//third_party/js:babel-plugin-transform-es2015-block-scoped-functions', | |
'//third_party/js:babel-plugin-transform-es2015-classes', | |
'//third_party/js:babel-plugin-transform-es2015-object-super', | |
'//third_party/js:babel-plugin-transform-es2015-shorthand-properties', | |
'//third_party/js:babel-plugin-transform-es2015-computed-properties', | |
'//third_party/js:babel-plugin-transform-es2015-for-of', | |
'//third_party/js:babel-plugin-transform-es2015-sticky-regex', | |
'//third_party/js:babel-plugin-transform-es2015-unicode-regex', | |
'//third_party/js:babel-plugin-check-es2015-constants', | |
'//third_party/js:babel-plugin-transform-es2015-spread', | |
'//third_party/js:babel-plugin-transform-es2015-parameters', | |
'//third_party/js:babel-plugin-transform-es2015-destructuring', | |
'//third_party/js:babel-plugin-transform-es2015-block-scoping', | |
'//third_party/js:babel-plugin-transform-es2015-typeof-symbol', | |
'//third_party/js:babel-polyfill', | |
'//third_party/js:babel-preset-es2015', | |
'//third_party/js:babel-preset-react', | |
'//third_party/js:babel-relay-plugin', | |
'//third_party/js:chokidar', | |
'//third_party/js:bluebird', | |
'//third_party/js:fs-extra', | |
'//third_party/js:imports-loader', | |
'//third_party/js:json-loader', | |
'//third_party/js:minimist', | |
'//third_party/js:react-native', | |
'//third_party/js:shader-loader', | |
'//third_party/js:webpack', | |
'//third_party/js:webpack-dev-server', | |
'//third_party/js:whatwg-fetch', | |
], | |
visibility=['PUBLIC'] | |
) |
This file contains hidden or 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
# npm_library(name='babel-plugin-transform-es2015-template-literals', version=babel_version, visibility=['PUBLIC'],) | |
npm_library(name='babel-plugin-transform-es2015-literals', version=babel_version, visibility=['PUBLIC'],) | |
npm_library(name='babel-plugin-transform-es2015-function-name', version=babel_version, visibility=['PUBLIC'],) | |
# npm_library(name='babel-plugin-transform-es2015-arrow-functions', version=babel_version, visibility=['PUBLIC'],) | |
npm_library(name='babel-plugin-transform-es2015-block-scoped-functions', version=babel_version, visibility=['PUBLIC'],) | |
# npm_library(name='babel-plugin-transform-es2015-classes', version=babel_version, visibility=['PUBLIC'],) | |
npm_library(name='babel-plugin-transform-es2015-object-super', version=babel_version, visibility=['PUBLIC'],) | |
# npm_library(name='babel-plugin-transform-es2015-shorthand-properties', version=babel_version, visibility=['PUBLIC'],) | |
# npm_library(name='babel-plugin-transform-es2015-computed-properties', version=babel_version, visibility=['PUBLIC'],) | |
# npm_library(name='babel-plugin-transform-es2015-for-of', version=babel_version, visibility=['PUBLIC'],) | |
npm_library(name='babel-plugin-transform-es2015-sticky-regex', version=babel_version, visibility=['PUBLIC'],) | |
npm_library(name='babel-plugin-transform-es2015-unicode-regex', version=babel_version, visibility=['PUBLIC'],) | |
npm_library(name='babel-plugin-check-es2015-constants', version=babel_version, visibility=['PUBLIC'],) | |
# npm_library(name='babel-plugin-transform-es2015-spread', version=babel_version, visibility=['PUBLIC'],) | |
# npm_library(name='babel-plugin-transform-es2015-parameters', version=babel_version, visibility=['PUBLIC'],) | |
# npm_library(name='babel-plugin-transform-es2015-destructuring', version=babel_version, visibility=['PUBLIC'],) | |
# npm_library(name='babel-plugin-transform-es2015-block-scoping', version=babel_version, visibility=['PUBLIC'],) | |
npm_library(name='babel-plugin-transform-es2015-typeof-symbol', version=babel_version, visibility=['PUBLIC'],) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment