Skip to content

Commit

Permalink
conditionally add uglifyjs plugin for npm run prod
Browse files Browse the repository at this point in the history
  • Loading branch information
jdan committed Feb 28, 2017
1 parent c20365a commit 6f277b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"scripts": {
"build": "npm run prod && npm run dev",
"prod": "webpack --config webpack.config.babel.js -p",
"prod": "NODE_ENV=production webpack --config webpack.config.babel.js",
"dev": "webpack --config webpack.config.babel.js -d --devtool hidden --output-filename=tota11y.js",
"lint": "eslint index.js plugins test utils",
"test": "mocha --require test/babel-hook test/*.js",
Expand Down
42 changes: 25 additions & 17 deletions webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ let veryimportant = postcss.plugin("veryimportant", function() {
let bannerTemplate = handlebars.compile(
fs.readFileSync("./templates/banner.handlebars", "utf-8"));

const plugins = [
// Add a banner to our bundles with a version number, date, and
// license info
new webpack.BannerPlugin(
bannerTemplate({
version: require("./package.json").version,
date: new Date().toISOString().slice(0, 10),
}),
{entryOnly: true}),

// Make the JSX pragma function available everywhere without the need
// to use "require"
new webpack.ProvidePlugin({
[options.jsxPragma]: path.join(__dirname, "utils", "element"),
}),
];

if (process.env.NODE_ENV === "production") {
plugins.push(
// Suppress uglifyJS warnings from node_modules/
new webpack.optimize.UglifyJsPlugin({compress: {warnings: false}})
)
}

module.exports = {
entry: {
app: "./index.js",
Expand All @@ -44,22 +68,6 @@ module.exports = {
},
],
},
plugins: [
// Add a banner to our bundles with a version number, date, and
// license info
new webpack.BannerPlugin(
bannerTemplate({
version: require("./package.json").version,
date: new Date().toISOString().slice(0, 10),
}),
{entryOnly: true}),

// Make the JSX pragma function available everywhere without the need
// to use "require"
new webpack.ProvidePlugin({
[options.jsxPragma]: path.join(__dirname, "utils", "element"),
}),
new webpack.optimize.UglifyJsPlugin({compress: {warnings: false}})
],
plugins,
postcss: [veryimportant, autoprefixer],
};

0 comments on commit 6f277b7

Please sign in to comment.