Skip to content

Commit

Permalink
Toolchain for building browser version
Browse files Browse the repository at this point in the history
see #16
  • Loading branch information
maxkoryukov committed Feb 22, 2017
1 parent 782d973 commit a8c554d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
presets: ["es2015"]
}
80 changes: 80 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"use strict"

const debug = require("debug")("route4me-dev:webpack")
const _ = require("lodash")
const path = require("path")
const webpack = require("webpack")
const packageJson = require("./package.json")

const distDir = path.join(__dirname, "dist")

// required to avoid loading entire `package.json` to
// browser-bundle
const packageJsonReplacement = _.pick(packageJson, [
"version"
])

const commonRules = {
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
}, {
test: /[\/\\]package\.json$/,
loader: "json-string-loader",
options: {
json: packageJsonReplacement
},
}
],

},
devtool: "source-map",
output: {
path: distDir,
filename: "route4me.js",
//libraryTarget: "web",
},
entry: "./src/index.js",
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: true,
sourceMap: true,
}),
new webpack.LoaderOptionsPlugin({
debug: true
}),
],
}

const configs = [{
output: {
path: path.resolve(distDir),
library: "route4me",
libraryTarget: "umd2",
},
}, {
output: {
path: path.resolve(distDir, "commonjs"),
library: "route4me",
libraryTarget: "commonjs2",
},
}, {
output: {
path: path.resolve(distDir, "amd"),
library: "route4me",
libraryTarget: "amd",
},
}]

let fullConfigs = _(configs)
.map(cfg => _.defaultsDeep({}, cfg, commonRules))
// because gulp-webpack can't handle multiple configs...
// TODO: search for workaround
.head()
//.value()

debug("WebPack config:", fullConfigs)
module.exports = fullConfigs

0 comments on commit a8c554d

Please sign in to comment.