webpack_rails 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94db163f3dd7211fe8a4448cebe146d2da8444f2
4
- data.tar.gz: 583bc5a7877aa766ac8be90e89ed08a32bbf71b3
3
+ metadata.gz: e9b1fd76152f832eb130b5c1565bcbabde788f78
4
+ data.tar.gz: 3c5192bb8d4e2c3d12733b08ea62932f9370c9cf
5
5
  SHA512:
6
- metadata.gz: 09c5915dc7d08bf0ee20454a705668cdf763474010e6e220794d0cef5affcaeee196b8c14cc7f5c5c71971923a35067b6ebe75be55bd9bf23b5e4b6b80af4921
7
- data.tar.gz: 12983a42d2d14ffc73f249d9afa7c25aaa63f6fed1d7d9172bf8311aaba3de477015202a854377339f8312b0c85dff9b96dc7caede640800006903995b276cec
6
+ metadata.gz: 84b22867941e1b5ca2040a30a68506499dd0379060b9ca622e8b29b0dac4325d65ba33e6a9ea2bd2d5af91f9af449ca705e4bfef5ae45ddd11b01b1f1b8b56fa
7
+ data.tar.gz: 5a5d175a7d84730c5187d7d8010db6eb813a8d06dcadab13ac326f853a46acb7cc29e0ee2c87238c37eff199eca674aa042ee93f1871f977a87265d80120b5f8
@@ -1,35 +1,50 @@
1
1
  var stripAnsi = require('strip-ansi');
2
2
  var jsStringEscape = require('js-string-escape');
3
3
 
4
- // expected to be installed by the gem consumer (eg. the app)
4
+ // webpack is expected to be installed by the gem consumer (eg. the app)
5
5
  var RawSource = require('webpack/lib/RawSource');
6
6
 
7
+ var errorTypePattern = /ModuleBuildError:[^:]*: /g;
8
+
7
9
  // a webpack plugin to inject js which renders a message upon error
8
10
  function ErrorMessagePlugin() {}
9
11
  ErrorMessagePlugin.prototype.apply = function(compiler) {
10
- compiler.plugin('emit', function(compilation, callback) {
12
+ // if there are errors, replace the output of any bundles with an error message
13
+ compiler.plugin('emit', function(compilation, done) {
11
14
  if (compilation.errors.length > 0) {
12
- var cleanedErrorMessage = cleanCompilationErrorMessages(compilation.errors);
13
- var errorPageHeader = ''+
14
- '<style>body { font-family: sans-serif; }</style>'+
15
- '<h1>Webpack Build Error</h1>';
16
-
17
- var errorJsCode = ''+
18
- 'document.body.className += " webpack-build-error";'+
19
- 'document.body.innerHTML = "'+errorPageHeader+'";\n'+
20
- 'var errorDisplay = document.createElement("pre");\n'+
21
- 'errorDisplay.textContent = "'+jsStringEscape(cleanedErrorMessage)+'";\n'+
22
- 'document.body.appendChild(errorDisplay);\n';
23
-
24
- Object.keys(compilation.assets).forEach(function(assetName) {
25
- compilation.assets[assetName] = new RawSource(errorJsCode)
26
- });
15
+ var errorJsCode = renderErrorJsCode(compilation.errors);
16
+
17
+ Object.keys(compilation.assets)
18
+ .filter(isABundle) // don't mess with hot-update assets
19
+ .forEach(function(assetName) {
20
+ compilation.assets[assetName] = new RawSource(errorJsCode);
21
+ });
27
22
  }
28
- callback();
23
+
24
+ done();
29
25
  }.bind(this));
30
26
  };
31
27
 
32
- var errorTypePattern = /ModuleBuildError:[^:]*: /g;
28
+ function isABundle(assetName) {
29
+ return /\.bundle\./.test(assetName);
30
+ }
31
+
32
+ function renderErrorJsCode(errors) {
33
+ var cleanedErrorMessage = cleanCompilationErrorMessages(errors);
34
+ var errorPageHeader = ''+
35
+ '<style>body { font-family: sans-serif; }</style>'+
36
+ '<h1>Webpack Build Error</h1>';
37
+
38
+ var errorJsCode = ''+
39
+ 'document.body.className += " webpack-build-error";'+
40
+ 'document.body.innerHTML = "'+errorPageHeader+'";\n'+
41
+ 'var errorDisplay = document.createElement("pre");\n'+
42
+ 'errorDisplay.textContent = "'+jsStringEscape(cleanedErrorMessage)+'";\n'+
43
+ 'document.body.appendChild(errorDisplay);\n';
44
+
45
+ return errorJsCode;
46
+ }
47
+
33
48
  function cleanCompilationErrorMessages(errors) {
34
49
  return stripAnsi(errors.join('\n\n')).replace(errorTypePattern, '');
35
50
  }
@@ -0,0 +1,19 @@
1
+ var fs = require('fs');
2
+
3
+ var loggingToFile = Boolean(process.env.WEBPACK_TASK_LOGGING);
4
+
5
+ function logLine(message) {
6
+ fs.appendFileSync('log/webpack-task.log', new Date()+' -- '+message+'\n');
7
+ }
8
+
9
+ function log(message) {
10
+ if (loggingToFile) logLine(message);
11
+ }
12
+
13
+ function logErr(err) {
14
+ logLine(err.toString()+' -- '+JSON.stringify(err.stack));
15
+ }
16
+
17
+ log.error = logErr;
18
+
19
+ module.exports = log;
@@ -1,4 +1,3 @@
1
- var fs = require('fs');
2
1
  var path = require('path');
3
2
  var xtend = require('xtend');
4
3
  var isArray = require('is-array');
@@ -12,10 +11,9 @@ var webpackDevMiddleware = require('webpack-dev-middleware');
12
11
  var webpackHotMiddleware = require('webpack-hot-middleware');
13
12
  var webpack = require('webpack');
14
13
 
14
+ var log = require('./log');
15
15
  var ErrorMessagePlugin = require('./ErrorMessagePlugin');
16
16
 
17
- var loggingToFile = Boolean(process.env.WEBPACK_TASK_LOGGING);
18
-
19
17
  process.on('exit', function(code) {
20
18
  log(process.pid+' About to exit with code:', code);
21
19
  });
@@ -30,7 +28,7 @@ module.exports = function waitForServer(opts, done) {
30
28
  log('starting webpack');
31
29
  runWebpackDevServer(opts, function(err, createdServer) {
32
30
  if (err) {
33
- logErr(err);
31
+ log.error(err);
34
32
  done(err);
35
33
  }
36
34
 
@@ -90,6 +88,7 @@ function makeDevServerConfig(opts) {
90
88
  new webpack.optimize.OccurenceOrderPlugin(),
91
89
  // https://webpack.github.io/docs/webpack-dev-server.html#hot-module-replacement
92
90
  new webpack.HotModuleReplacementPlugin(),
91
+ new webpack.NoErrorsPlugin(),
93
92
  new ErrorMessagePlugin(),
94
93
  ]),
95
94
  });
@@ -113,10 +112,5 @@ function makeDevServerConfig(opts) {
113
112
  return devServerConfig;
114
113
  }
115
114
 
116
- function log(message) {
117
- if (loggingToFile) fs.appendFileSync('log/webpack-task.log', new Date()+' -- '+message+'\n');
118
- }
119
115
 
120
- function logErr(err) {
121
- log(err.toString()+' -- '+JSON.stringify(err.stack));
122
- }
116
+
@@ -2,11 +2,7 @@ var webpack = require('webpack');
2
2
  var fs = require('fs');
3
3
  var path = require('path');
4
4
 
5
- var stdoutLogging = process.env.WEBPACK_STDOUT_LOGGING;
6
- var loggingToFile = true;
7
- function log(message) {
8
- if (loggingToFile) fs.appendFile('log/webpack-task.log', message+'\n');
9
- }
5
+ var log = require('./log');
10
6
 
11
7
  // TODO: add support for multiple builds using multiple webpack configs which
12
8
  // can each be waited upon independently
@@ -22,8 +18,6 @@ var lastBuildResult = null;
22
18
  function buildComplete(buildResult) {
23
19
  lastBuildResult = buildResult;
24
20
 
25
- if (stdoutLogging) console.log('rebuild complete');
26
-
27
21
  currentBuildCallbacks.forEach(function(callback) {
28
22
  log('async completion callback');
29
23
  callback(buildResult);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpack_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Friend
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-26 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: node_task
@@ -48,6 +48,7 @@ files:
48
48
  - lib/webpack_rails.rb
49
49
  - lib/webpack_rails/ErrorMessagePlugin.js
50
50
  - lib/webpack_rails/engine.rb
51
+ - lib/webpack_rails/log.js
51
52
  - lib/webpack_rails/node_modules/cors/CONTRIBUTING.md
52
53
  - lib/webpack_rails/node_modules/cors/LICENSE
53
54
  - lib/webpack_rails/node_modules/cors/README.md