Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
4.1.0 - Add production sourcemaps (#433)
Browse files Browse the repository at this point in the history
- Add `devtool`, `uglifyJsPlugin`, and `definePlugin` environment options
- [Autoset `uglifyJsPlugin.sourceMap` to `true`](webpack/webpack#2704 (comment)) if `production.devtool` is defined
  • Loading branch information
Dan Tello committed May 9, 2017
1 parent 1cc7abc commit f78c858
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## 4.1.0
- Add `devtool`, `uglifyJsPlugin`, and `definePlugin` environment options
- [Autoset `uglifyJsPlugin.sourceMap` to `true`](https://github.com/webpack/webpack/issues/2704#issuecomment-228860162) if `production.devtool` is defined
- Add `publicPath` to Craft task-config.js [#432](https://github.com/vigetlabs/blendid/issues/432)

## 4.0.1
- add watchOptions to browserSync config [#429](https://github.com/vigetlabs/blendid/pull/429)
Expand Down
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,30 @@ Define additional webpack plugins that should be used in all environments
Define additional webpack loaders that should be used in all environments. Adds to `webpackConfig.module.rules`

#### `development`, `production`
Define additional webpack plugins and loaders for development or production environments
Specify additional environment specific configuration to be merged in with Blendid's defaults

- [`devtool`](https://webpack.js.org/configuration/devtool/#devtool)
- [`plugins`](https://webpack.js.org/concepts/plugins/)
- [`loaders`](https://webpack.js.org/concepts/loaders/)

_Production Only:_

- [`uglifyJsPlugin`](https://webpack.js.org/plugins/uglifyjs-webpack-plugin/#options)
- [`definePlugin`](https://webpack.js.org/plugins/define-plugin)

Note that if `devtool` is set in production, Blendid will automatically[set to `uglifyJsPlugin.sourceMap` to `true`](https://github.com/webpack/webpack/issues/2704#issuecomment-228860162).

**Example:**

```js
development: {
production: {
devtool: 'hidden-source-map',
uglifyJsPlugin: {
extractComments: true
},
definePlugin: {
SOME_API_KEY: 'abcdefg'
},
plugins: (webpack) => { return [ new webpack.IgnorePlugin(/jsdom$/) ] },
loaders: [] // Adds to `webpackConfig.module.rules`
}
Expand Down
11 changes: 11 additions & 0 deletions gulpfile.js/lib/task-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
quiet: true,
react: false
},
devtool: 'eval-cheap-module-source-map',
babelLoader: {
// "test" is derived from TASK_CONFIG.javascripts.extensions
// "options" is derived from TASK_CONFIG.javascripts.babel
Expand All @@ -19,6 +20,16 @@ module.exports = {
},
babel: {
presets: [["es2015", { "modules": false }], 'stage-1']
},
development: {},
production: {
devtool: false,
uglifyJsPlugin: {},
definePlugin: {
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}
}
},

Expand Down
16 changes: 9 additions & 7 deletions gulpfile.js/lib/webpack-multi-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = function (env) {
}

if (env === 'development') {
webpackConfig.devtool = TASK_CONFIG.javascripts.devtool || 'eval-cheap-module-source-map'
webpackConfig.devtool = TASK_CONFIG.javascripts.development.devtool || TASK_CONFIG.javascripts.devtool || false
webpackConfig.output.pathinfo = true

// Create new entry object with webpack-hot-middleware and react-hot-loader (if enabled)
Expand All @@ -78,13 +78,15 @@ module.exports = function (env) {
webpackConfig.plugins.push(new webpackManifest(PATH_CONFIG.javascripts.dest, PATH_CONFIG.dest))
}

const uglfiyConfig = TASK_CONFIG.javascripts.production.uglifyJsPlugin
if(TASK_CONFIG.javascripts.production.devtool) {
uglfiyConfig.sourceMap = true
}

webpackConfig.devtool = TASK_CONFIG.javascripts.production.devtool
webpackConfig.plugins.push(
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin(),
new webpack.DefinePlugin(TASK_CONFIG.javascripts.production.definePlugin),
new webpack.optimize.UglifyJsPlugin(uglfiyConfig),
new webpack.NoEmitOnErrorsPlugin()
)
}
Expand Down
20 changes: 11 additions & 9 deletions gulpfile.js/lib/webpackManifest.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
var path = require('path')
var fs = require('fs')
const path = require('path')
const fs = require('fs')

module.exports = function(jsDest, dest, filename) {
filename = filename || 'rev-manifest.json'

return function() {
this.plugin("done", function(stats) {
var stats = stats.toJson()
var chunks = stats.assetsByChunkName
var manifest = {}
this.plugin("done", function(statsObject) {
const stats = statsObject.toJson()
const chunks = stats.assetsByChunkName
const manifest = {}

for (var key in chunks) {
var originalFilename = key + '.js'
manifest[path.join(jsDest, originalFilename)] = path.join(jsDest, chunks[key])
for (let key in chunks) {
const originalFilename = key + '.js'
// https://github.com/vigetlabs/blendid/issues/232#issuecomment-171963233
const chunkName = typeof chunks[key] === 'string' ? chunks[key] : chunks[key][0]
manifest[path.join(jsDest, originalFilename)] = path.join(jsDest, chunkName)
}

fs.writeFileSync(
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js/tasks/rev/rev-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var revNapkin = require('gulp-rev-napkin');
// 1) Add md5 hashes to assets referenced by CSS and JS files
gulp.task('rev-assets', function() {
// Ignore files that may reference assets. We'll rev them next.
var ignoreThese = '!' + path.resolve(process.env.PWD, PATH_CONFIG.dest,'**/*+(css|js|json|html)')
var ignoreThese = '!' + path.resolve(process.env.PWD, PATH_CONFIG.dest,'**/*+(css|js|map|json|html)')

return gulp.src([path.resolve(process.env.PWD, PATH_CONFIG.dest,'**/*'), ignoreThese])
.pipe(rev())
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blendid",
"version": "4.0.1",
"version": "4.1.0",
"description": "(formerly gulp-starter) A full featured configurable gulp asset pipeline and static site builder",
"license": "MIT",
"engines": {
Expand Down

0 comments on commit f78c858

Please sign in to comment.