-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Toolchain for building browser version
see #16
- Loading branch information
1 parent
782d973
commit a8c554d
Showing
2 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
presets: ["es2015"] | ||
} |
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,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 |