webpack-isomorphic-tools
Advanced tools
Comparing version 0.3.6 to 0.4.0
@@ -33,6 +33,10 @@ 'use strict'; | ||
var _pluginsWriteStats = require('./plugins/write stats'); | ||
var _toolsSerializeJavascript = require('./tools/serialize-javascript'); | ||
var _pluginsWriteStats2 = _interopRequireDefault(_pluginsWriteStats); | ||
var _toolsSerializeJavascript2 = _interopRequireDefault(_toolsSerializeJavascript); | ||
var _pluginsWriteAssets = require('./plugins/write assets'); | ||
var _pluginsWriteAssets2 = _interopRequireDefault(_pluginsWriteAssets); | ||
var _pluginsNotifyStats = require('./plugins/notify stats'); | ||
@@ -57,3 +61,5 @@ | ||
if (!this.options.assets) { | ||
throw new Error('You must specify "assets" parameter'); | ||
this.options.assets = [] | ||
// throw new Error('You must specify "assets" parameter') | ||
; | ||
} | ||
@@ -80,3 +86,8 @@ | ||
this.options.webpack_assets_file_path = this.options.webpack_assets_file_path || 'webpack-assets.json'; | ||
this.require_cache = []; | ||
this.debug('options:'); | ||
this.debug(this.options); | ||
} | ||
@@ -89,2 +100,10 @@ | ||
value: function populate(webpack_configuration) { | ||
this.debug('populating webpack configuration'); | ||
// ensure the "module.loaders" path exists inside webpack configuration | ||
webpack_configuration.module = webpack_configuration.module || {}; | ||
webpack_configuration.module.loaders = webpack_configuration.module.loaders || {}; | ||
// assets regular expressions (based on extensions). | ||
// will be used in loaders and in write_assets | ||
var regular_expressions = {}; | ||
@@ -121,2 +140,3 @@ | ||
// specify the loader (or loaders) | ||
if (description.loader) { | ||
@@ -128,2 +148,3 @@ loader.loader = description.loader; | ||
// restrict the loader to specific paths if needed | ||
if (description.path || description.paths) { | ||
@@ -133,10 +154,9 @@ loader.include = description.paths || [description.path]; | ||
if (!webpack_configuration.module) { | ||
webpack_configuration.module = {}; | ||
} | ||
this.debug('adding webpack loader:'); | ||
// simple JSON.stringify won't suffice | ||
// because loader's test property is a regular expression | ||
// (but serialize-javascript does no indentation) | ||
this.debug((0, _toolsSerializeJavascript2['default'])(loader)); | ||
if (!webpack_configuration.module.loaders) { | ||
webpack_configuration.module.loaders = {}; | ||
} | ||
// add the loader to webpack configuration | ||
webpack_configuration.module.loaders.push(loader); | ||
@@ -160,22 +180,25 @@ } | ||
// webpack-stats.json file path | ||
var webpack_stats_file_path = this.webpack_stats_path(); | ||
// webpack-assets.json file path | ||
var webpack_assets_file_path = this.webpack_assets_path(); | ||
// add webpack stats plugins | ||
// add webpack assets plugins | ||
// selfie | ||
var tools = this; | ||
var options = this.options; | ||
// write_stats writes webpack compiled files' names to a special .json file | ||
// write_assets writes webpack compiled files' names to a special .json file | ||
// (this will be used later to fetch these files from server) | ||
function write_stats_plugin() { | ||
function write_assets_plugin() { | ||
this.plugin('done', function (stats) { | ||
_pluginsWriteStats2['default'].call(this, stats, { | ||
_pluginsWriteAssets2['default'].call(this, stats, { | ||
environment: options.development ? 'development' : 'production', | ||
output_file: webpack_stats_file_path, | ||
debug: options.debug, | ||
output_file: webpack_assets_file_path, | ||
output: function output() { | ||
return tools.default_webpack_stats(); | ||
return tools.default_webpack_assets(); | ||
}, | ||
assets: options.assets, | ||
regular_expressions: regular_expressions | ||
regular_expressions: regular_expressions, | ||
log: { info: tools.info.bind(tools), debug: tools.debug.bind(tools), error: tools.error.bind(tools) } | ||
}); | ||
@@ -193,5 +216,5 @@ }); | ||
this.plugin('done', _pluginsNotifyStats2['default']); | ||
}, write_stats_plugin); | ||
}, write_assets_plugin); | ||
} else { | ||
webpack_configuration.plugins = webpack_configuration.plugins.concat(write_stats_plugin); | ||
webpack_configuration.plugins = webpack_configuration.plugins.concat(write_assets_plugin); | ||
} | ||
@@ -203,10 +226,14 @@ | ||
}, { | ||
key: 'webpack_stats_path', | ||
key: 'webpack_assets_path', | ||
// gets webpack-stats.json file path | ||
value: function webpack_stats_path() { | ||
if (this.options.webpack_stats_file_path) { | ||
return _path3['default'].resolve(this.options.project_path, this.options.webpack_stats_file_path); | ||
} | ||
return _path3['default'].resolve(this.options.webpack_output_path, '..', 'webpack-stats.json'); | ||
// gets webpack-assets.json file path | ||
value: function webpack_assets_path() { | ||
return _path3['default'].resolve(this.options.project_path, this.options.webpack_assets_file_path) | ||
// if (this.options.webpack_assets_file_path) | ||
// { | ||
// return path.resolve(this.options.project_path, this.options.webpack_assets_file_path) | ||
// } | ||
// return path.resolve(this.options.webpack_output_path, '..', 'webpack-assets.json') | ||
; | ||
} | ||
@@ -220,34 +247,19 @@ }, { | ||
// webpack and node.js start in parallel | ||
// so webpack-stats.json might not exist on the very first run | ||
// so webpack-assets.json might not exist on the very first run | ||
// (or there should be a better way of webpack notifying about build ending) | ||
if (!_fs2['default'].existsSync(this.webpack_stats_path())) { | ||
console.log(_colorsSafe2['default'].red('***** File "' + this.webpack_stats_path() + '" not found. Using an empty stub instead.')); | ||
return this.default_webpack_stats(); | ||
if (!_fs2['default'].existsSync(this.webpack_assets_path())) { | ||
this.error('"' + this.webpack_assets_path() + '" not found. Using an empty stub instead'); | ||
return this.default_webpack_assets(); | ||
} | ||
var assets = require(this.webpack_stats_path()); | ||
// // invalidate caches with empty data | ||
// // a better way would be to keep track of all the required modules in require() | ||
// for (let assets_type of Object.keys(assets)) | ||
// { | ||
// const assets_of_type = assets[assets_type] | ||
// for (let path of Object.keys(assets_of_type)) | ||
// { | ||
// const real_path = assets_of_type[path] | ||
// // http://... | ||
// delete require.cache[require.resolve(real_path)] | ||
// } | ||
// } | ||
return assets; | ||
return require(this.webpack_assets_path()); | ||
} | ||
}, { | ||
key: 'default_webpack_stats', | ||
key: 'default_webpack_assets', | ||
// returns a stub for webpack-stats.json | ||
// returns a stub for webpack-assets.json | ||
// (because it doesn't exist on the very first run) | ||
// https://github.com/halt-hammerzeit/webpack-isomorphic-tools#race-condition-looking-for-a-solution | ||
value: function default_webpack_stats() { | ||
var webpack_stats = { | ||
value: function default_webpack_assets() { | ||
var webpack_assets = { | ||
javascript: {}, | ||
@@ -257,3 +269,3 @@ styles: {} | ||
return webpack_stats; | ||
return webpack_assets; | ||
} | ||
@@ -265,4 +277,7 @@ }, { | ||
value: function refresh() { | ||
delete require.cache[this.webpack_stats_path()]; | ||
this.debug('refreshing'); | ||
// uncache webpack-assets.json file | ||
delete require.cache[this.webpack_assets_path()]; | ||
// uncache cached assets | ||
@@ -277,3 +292,3 @@ var _iteratorNormalCompletion2 = true; | ||
// console.log('Flushing cache for', path) | ||
this.debug('flushing require() cache for ' + _path); | ||
delete require.cache[_path]; | ||
@@ -308,6 +323,7 @@ } | ||
this.debug('registering require() hooks for assets'); | ||
// for each user specified asset type which isn't for .js files | ||
// (because '.js' files requiring already works natively) | ||
_Object$keys(this.options.assets).filter(function (assets_type) { | ||
var description = _this.options.assets[assets_type]; | ||
this.options.assets.filter(function (description) { | ||
if (description.extension) { | ||
@@ -320,4 +336,3 @@ return description.extension !== 'js'; | ||
// register a require hook for each file extension of this asset type | ||
.forEach(function (assets_type) { | ||
var description = _this.options.assets[assets_type]; | ||
.forEach(function (description) { | ||
(description.extensions || [description.extension]).forEach(function (extension) { | ||
@@ -337,2 +352,4 @@ _this.register_extension(extension); | ||
value: function require(asset_path) { | ||
this.debug('requiring ' + asset_path); | ||
if (!asset_path) { | ||
@@ -342,4 +359,2 @@ return ''; | ||
// console.log('* Requiring', asset_path) | ||
// get real file path list | ||
@@ -379,3 +394,3 @@ var assets = this.assets(); | ||
// serve a not-found asset maybe | ||
console.log(_colorsSafe2['default'].red('***** Asset not found: ' + asset_path)); | ||
this.error('asset not found: ' + asset_path); | ||
return ''; | ||
@@ -390,4 +405,6 @@ } | ||
this.debug('registering a require() hook for extension ' + extension); | ||
_toolsNodeHook2['default'].hook('.' + extension, function (asset_path, fallback) { | ||
// console.log('Requiring', asset_path) | ||
_this2.debug('require() hook fired for ' + asset_path); | ||
@@ -410,2 +427,3 @@ // track cached assets | ||
if (_this2.options.exceptions.indexOf(asset_path) >= 0) { | ||
_this2.debug('skipping require call for ' + asset_path); | ||
return fallback(); | ||
@@ -421,3 +439,3 @@ } | ||
// waits for webpack-stats.json to be created after Webpack build process finishes | ||
// waits for webpack-assets.json to be created after Webpack build process finishes | ||
value: function ready(done) { | ||
@@ -428,2 +446,5 @@ var _this3 = this; | ||
// selfie | ||
var tools = this; | ||
function wait_for(condition, proceed) { | ||
@@ -434,3 +455,6 @@ function check() { | ||
} | ||
console.log('(waiting for the first Webpack build to finish)'); | ||
tools.debug(tools.webpack_assets_path() + ' not found'); | ||
tools.info('(waiting for the first Webpack build to finish)'); | ||
setTimeout(check, interval); | ||
@@ -443,3 +467,3 @@ } | ||
wait_for(function () { | ||
return _fs2['default'].existsSync(_this3.webpack_stats_path()); | ||
return _fs2['default'].existsSync(_this3.webpack_assets_path()); | ||
}, done); | ||
@@ -450,2 +474,19 @@ | ||
} | ||
}, { | ||
key: 'info', | ||
value: function info(message) { | ||
console.log(log_preamble, generate_log_message(message)); | ||
} | ||
}, { | ||
key: 'debug', | ||
value: function debug(message) { | ||
if (this.options.debug) { | ||
console.log(log_preamble, '[debug]', generate_log_message(message)); | ||
} | ||
} | ||
}, { | ||
key: 'error', | ||
value: function error(message) { | ||
console.log(_colorsSafe2['default'].red(log_preamble, '[error]', generate_log_message(message))); | ||
} | ||
}]); | ||
@@ -471,3 +512,3 @@ | ||
// if it wasn't embedded then it's a file path so resolve it | ||
asset_path = options.output_path + asset_path; | ||
asset_path = options.assets_base_path + asset_path; | ||
} | ||
@@ -477,3 +518,14 @@ | ||
}; | ||
// transforms arguments to text | ||
function generate_log_message(message) { | ||
if (typeof message === 'object') { | ||
return JSON.stringify(message, null, 2); | ||
} | ||
return message; | ||
} | ||
// is prepended to console output | ||
var log_preamble = '[webpack-isomorphic-tools]'; | ||
module.exports = exports['default']; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "webpack-isomorphic-tools", | ||
"version": "0.3.6", | ||
"version": "0.4.0", | ||
"description": "Transforms CSS-alike text into a React style JSON object", | ||
@@ -5,0 +5,0 @@ "main": "babel-transpiled-modules/index.js", |
140
README.md
@@ -121,10 +121,5 @@ # webpack-isomorphic-tools | ||
{ | ||
// if this is the configuration for webpack-dev-server | ||
development: true, // false by default | ||
// development mode (supports assets hot reload) | ||
development: true, | ||
// by default it creates 'webpack-stats.json' file | ||
// one level higher than your Webpack output.path. | ||
// if you want you can change the stats file path as you want: | ||
// webpack_stats_file_path: 'webpack-stats.json' // relative to your project folder | ||
assets: | ||
@@ -134,7 +129,3 @@ [{ | ||
loader: 'url-loader?limit=10240', // any image below or equal to 10K will be converted to inline base64 instead | ||
// loaders: ['you can specify a list of loaders too'] | ||
// or you can specify no loader at all and in that case no module loader would be added to webpack | ||
// path: 'you can constrain loading assets by path' | ||
// paths: ['or by a list of paths'] | ||
parser: Webpack_isomorphic_tools.url_loader_parser // you don't need to know what this function does but you can always look at the sources (it's an extension point along with a couple more) | ||
parser: Webpack_isomorphic_tools.url_loader_parser // it just works; see the Configuration section for more info | ||
}] | ||
@@ -287,2 +278,127 @@ } | ||
## Configuration | ||
Available configuration parameters: | ||
```javascript | ||
{ | ||
// is it development or production? | ||
// set this to true, for example, if this is | ||
// the configuration for webpack-dev-server | ||
// (enables asset hot reloading). | ||
development: true, // is false by default | ||
// debug mode. | ||
// when set to true, lets you see debugging messages in the console, | ||
// and also outputs 'webpack-stats.debug.json' file with Webpack stats. | ||
// (you'll be interested in the contents of this file | ||
// in case you're writing your own filter, naming or parser | ||
// for some asset type) | ||
debug: true, // is false by default | ||
// By default it creates 'webpack-assets.json' file one level higher | ||
// than your webpack_configuration.output.path (which is your project path). | ||
// You can change the stats file path as you want | ||
// (therefore changing both folder and filename). | ||
// | ||
// The folder derived from this parameter will also be used | ||
// to store 'webpack-stats.debug.json' file in case you're in debug mode | ||
// | ||
// (relative to webpack_configuration.output.path which is your project folder) | ||
// (these aren't actually 'stats', these are some values derived from Webpack 'stats') | ||
webpack_assets_file_path: 'webpack-stats.json', // is 'webpack-assets.json' by default | ||
// here you can define all your asset types | ||
assets: | ||
[{ | ||
// you can omit this parameter | ||
name: "appears in webpack-assets.json, is autogenerated by default", | ||
// setting these will result in creating a webpack module loader | ||
loader: 'webpack loader string', | ||
loaders: ['webpack loader No 1 string', 'webpack loader No 2 string', ...], | ||
// or you can specify no "loader" (and no "loaders") at all | ||
// and in that case no module loader would be added | ||
// to webpack configuration for this asset type | ||
// setting these will result in | ||
// webpack module loader "include" property | ||
path: 'you can optionally constrain assets by path', | ||
paths: ['or by a list of paths'], | ||
// [optional] | ||
// | ||
// transforms a webpack stats module name | ||
// to an asset name | ||
// | ||
// arguments: | ||
// | ||
// module - a webpack stats module | ||
// | ||
// options - various options | ||
// (development or production mode, | ||
// "debug" flag, | ||
// assets base path (on the disk or on the network), | ||
// regular_expressions{} for each asset type (by name), | ||
// "log" object (for logging)) | ||
// | ||
// returns: a String | ||
// | ||
// by default is: "return module.name" | ||
// | ||
naming: function(module) { ... }, | ||
// [optional] | ||
// | ||
// determines which webpack stats modules | ||
// belong to this asset type | ||
// | ||
// arguments: | ||
// | ||
// module - a webpack stats module | ||
// | ||
// regular_expression - a regular expression | ||
// composed of this asset type's extensions | ||
// e.g. /\.scss$/, /\.(ico|gif)$/ | ||
// | ||
// options - various options | ||
// (development or production mode, | ||
// "debug" flag, | ||
// assets base path (on the disk or on the network), | ||
// regular_expressions{} for each asset type (by name), | ||
// "log" object (for logging)) | ||
// | ||
// returns: a Boolean | ||
// | ||
// by default is: "return regular_expression.test(module.name)" | ||
// | ||
filter: function(module, regular_expression, options) { ... }, | ||
// [required] | ||
// | ||
// parses a webpack stats module | ||
// to whatever you need to get | ||
// when you require() these assets | ||
// in your code later on | ||
// | ||
// arguments: | ||
// | ||
// module - a webpack stats module | ||
// | ||
// options - various options | ||
// (development or production mode, | ||
// "debug" flag, | ||
// assets base path (on the disk or on the network), | ||
// regular_expressions{} for each asset type (by name), | ||
// "log" object (for logging)) | ||
// | ||
// returns: whatever (could be a filename, could be a JSON object) | ||
// | ||
parser: function(module, options) { ... } | ||
}, | ||
...] | ||
} | ||
``` | ||
## Gotchas | ||
@@ -289,0 +405,0 @@ |
@@ -5,5 +5,6 @@ import path from 'path' | ||
import hook from './tools/node-hook' | ||
import hook from './tools/node-hook' | ||
import serialize from './tools/serialize-javascript' | ||
import write_stats from './plugins/write stats' | ||
import write_assets from './plugins/write assets' | ||
import notify_stats from './plugins/notify stats' | ||
@@ -26,3 +27,4 @@ | ||
{ | ||
throw new Error('You must specify "assets" parameter') | ||
this.options.assets = [] | ||
// throw new Error('You must specify "assets" parameter') | ||
} | ||
@@ -53,3 +55,8 @@ | ||
this.options.webpack_assets_file_path = this.options.webpack_assets_file_path || 'webpack-assets.json' | ||
this.require_cache = [] | ||
this.debug('options:') | ||
this.debug(this.options) | ||
} | ||
@@ -60,2 +67,10 @@ | ||
{ | ||
this.debug('populating webpack configuration') | ||
// ensure the "module.loaders" path exists inside webpack configuration | ||
webpack_configuration.module = webpack_configuration.module || {} | ||
webpack_configuration.module.loaders = webpack_configuration.module.loaders || {} | ||
// assets regular expressions (based on extensions). | ||
// will be used in loaders and in write_assets | ||
const regular_expressions = {} | ||
@@ -91,2 +106,3 @@ | ||
// specify the loader (or loaders) | ||
if (description.loader) | ||
@@ -101,2 +117,3 @@ { | ||
// restrict the loader to specific paths if needed | ||
if (description.path || description.paths) | ||
@@ -107,12 +124,9 @@ { | ||
if (!webpack_configuration.module) | ||
{ | ||
webpack_configuration.module = {} | ||
} | ||
this.debug('adding webpack loader:') | ||
// simple JSON.stringify won't suffice | ||
// because loader's test property is a regular expression | ||
// (but serialize-javascript does no indentation) | ||
this.debug(serialize(loader)) | ||
if (!webpack_configuration.module.loaders) | ||
{ | ||
webpack_configuration.module.loaders = {} | ||
} | ||
// add the loader to webpack configuration | ||
webpack_configuration.module.loaders.push(loader) | ||
@@ -122,23 +136,26 @@ } | ||
// webpack-stats.json file path | ||
const webpack_stats_file_path = this.webpack_stats_path() | ||
// webpack-assets.json file path | ||
const webpack_assets_file_path = this.webpack_assets_path() | ||
// add webpack stats plugins | ||
// add webpack assets plugins | ||
// selfie | ||
const tools = this | ||
const options = this.options | ||
// write_stats writes webpack compiled files' names to a special .json file | ||
// write_assets writes webpack compiled files' names to a special .json file | ||
// (this will be used later to fetch these files from server) | ||
function write_stats_plugin() | ||
function write_assets_plugin() | ||
{ | ||
this.plugin('done', function(stats) | ||
{ | ||
write_stats.call(this, stats, | ||
write_assets.call(this, stats, | ||
{ | ||
environment : options.development ? 'development' : 'production', | ||
output_file : webpack_stats_file_path, | ||
output : () => tools.default_webpack_stats(), | ||
debug : options.debug, | ||
output_file : webpack_assets_file_path, | ||
output : () => tools.default_webpack_assets(), | ||
assets : options.assets, | ||
regular_expressions : regular_expressions | ||
regular_expressions : regular_expressions, | ||
log : { info: tools.info.bind(tools), debug: tools.debug.bind(tools), error: tools.error.bind(tools) } | ||
}) | ||
@@ -161,3 +178,3 @@ }) | ||
write_stats_plugin | ||
write_assets_plugin | ||
) | ||
@@ -169,3 +186,3 @@ } | ||
( | ||
write_stats_plugin | ||
write_assets_plugin | ||
) | ||
@@ -178,10 +195,12 @@ } | ||
// gets webpack-stats.json file path | ||
webpack_stats_path() | ||
// gets webpack-assets.json file path | ||
webpack_assets_path() | ||
{ | ||
if (this.options.webpack_stats_file_path) | ||
{ | ||
return path.resolve(this.options.project_path, this.options.webpack_stats_file_path) | ||
} | ||
return path.resolve(this.options.webpack_output_path, '..', 'webpack-stats.json') | ||
return path.resolve(this.options.project_path, this.options.webpack_assets_file_path) | ||
// if (this.options.webpack_assets_file_path) | ||
// { | ||
// return path.resolve(this.options.project_path, this.options.webpack_assets_file_path) | ||
// } | ||
// return path.resolve(this.options.webpack_output_path, '..', 'webpack-assets.json') | ||
} | ||
@@ -194,34 +213,19 @@ | ||
// webpack and node.js start in parallel | ||
// so webpack-stats.json might not exist on the very first run | ||
// so webpack-assets.json might not exist on the very first run | ||
// (or there should be a better way of webpack notifying about build ending) | ||
if (!fs.existsSync(this.webpack_stats_path())) | ||
if (!fs.existsSync(this.webpack_assets_path())) | ||
{ | ||
console.log(colors.red(`***** File "${this.webpack_stats_path()}" not found. Using an empty stub instead.`)) | ||
return this.default_webpack_stats() | ||
this.error(`"${this.webpack_assets_path()}" not found. Using an empty stub instead`) | ||
return this.default_webpack_assets() | ||
} | ||
const assets = require(this.webpack_stats_path()) | ||
// // invalidate caches with empty data | ||
// // a better way would be to keep track of all the required modules in require() | ||
// for (let assets_type of Object.keys(assets)) | ||
// { | ||
// const assets_of_type = assets[assets_type] | ||
// for (let path of Object.keys(assets_of_type)) | ||
// { | ||
// const real_path = assets_of_type[path] | ||
// // http://... | ||
// delete require.cache[require.resolve(real_path)] | ||
// } | ||
// } | ||
return assets | ||
return require(this.webpack_assets_path()) | ||
} | ||
// returns a stub for webpack-stats.json | ||
// returns a stub for webpack-assets.json | ||
// (because it doesn't exist on the very first run) | ||
// https://github.com/halt-hammerzeit/webpack-isomorphic-tools#race-condition-looking-for-a-solution | ||
default_webpack_stats() | ||
default_webpack_assets() | ||
{ | ||
const webpack_stats = | ||
const webpack_assets = | ||
{ | ||
@@ -232,3 +236,3 @@ javascript: {}, | ||
return webpack_stats | ||
return webpack_assets | ||
} | ||
@@ -239,8 +243,11 @@ | ||
{ | ||
delete require.cache[this.webpack_stats_path()] | ||
this.debug('refreshing') | ||
// uncache webpack-assets.json file | ||
delete require.cache[this.webpack_assets_path()] | ||
// uncache cached assets | ||
for (let path of this.require_cache) | ||
{ | ||
// console.log('Flushing cache for', path) | ||
this.debug(`flushing require() cache for ${path}`) | ||
delete require.cache[path] | ||
@@ -258,7 +265,8 @@ } | ||
{ | ||
this.debug('registering require() hooks for assets') | ||
// for each user specified asset type which isn't for .js files | ||
// (because '.js' files requiring already works natively) | ||
Object.keys(this.options.assets).filter(assets_type => | ||
this.options.assets.filter(description => | ||
{ | ||
const description = this.options.assets[assets_type] | ||
if (description.extension) | ||
@@ -274,5 +282,4 @@ { | ||
// register a require hook for each file extension of this asset type | ||
.forEach(assets_type => | ||
.forEach(description => | ||
{ | ||
const description = this.options.assets[assets_type]; | ||
(description.extensions || [description.extension]).forEach(extension => | ||
@@ -292,2 +299,4 @@ { | ||
{ | ||
this.debug(`requiring ${asset_path}`) | ||
if (!asset_path) | ||
@@ -298,4 +307,2 @@ { | ||
// console.log('* Requiring', asset_path) | ||
// get real file path list | ||
@@ -316,3 +323,3 @@ var assets = this.assets() | ||
// serve a not-found asset maybe | ||
console.log(colors.red(`***** Asset not found: ${asset_path}`)) | ||
this.error(`asset not found: ${asset_path}`) | ||
return '' | ||
@@ -324,5 +331,7 @@ } | ||
{ | ||
this.debug(`registering a require() hook for extension ${extension}`) | ||
hook.hook(`.${extension}`, (asset_path, fallback) => | ||
{ | ||
// console.log('Requiring', asset_path) | ||
this.debug(`require() hook fired for ${asset_path}`) | ||
@@ -347,2 +356,3 @@ // track cached assets | ||
{ | ||
this.debug(`skipping require call for ${asset_path}`) | ||
return fallback() | ||
@@ -356,3 +366,3 @@ } | ||
// waits for webpack-stats.json to be created after Webpack build process finishes | ||
// waits for webpack-assets.json to be created after Webpack build process finishes | ||
ready(done) | ||
@@ -362,2 +372,5 @@ { | ||
// selfie | ||
const tools = this | ||
function wait_for(condition, proceed) | ||
@@ -371,3 +384,6 @@ { | ||
} | ||
console.log('(waiting for the first Webpack build to finish)') | ||
tools.debug(`${tools.webpack_assets_path()} not found`) | ||
tools.info('(waiting for the first Webpack build to finish)') | ||
setTimeout(check, interval) | ||
@@ -379,3 +395,3 @@ } | ||
wait_for(() => fs.existsSync(this.webpack_stats_path()), done) | ||
wait_for(() => fs.existsSync(this.webpack_assets_path()), done) | ||
@@ -385,2 +401,20 @@ // allows chaining | ||
} | ||
info(message) | ||
{ | ||
console.log(log_preamble, generate_log_message(message)) | ||
} | ||
debug(message) | ||
{ | ||
if (this.options.debug) | ||
{ | ||
console.log(log_preamble, '[debug]', generate_log_message(message)) | ||
} | ||
} | ||
error(message) | ||
{ | ||
console.log(colors.red(log_preamble, '[error]', generate_log_message(message))) | ||
} | ||
} | ||
@@ -403,6 +437,19 @@ | ||
// if it wasn't embedded then it's a file path so resolve it | ||
asset_path = options.output_path + asset_path | ||
asset_path = options.assets_base_path + asset_path | ||
} | ||
return asset_path | ||
} | ||
} | ||
// transforms arguments to text | ||
function generate_log_message(message) | ||
{ | ||
if (typeof message === 'object') | ||
{ | ||
return JSON.stringify(message, null, 2) | ||
} | ||
return message | ||
} | ||
// is prepended to console output | ||
const log_preamble = '[webpack-isomorphic-tools]' |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
150214
32
2121
504
15