Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mixin loader and client-side mixin running
- Loading branch information
Showing
12 changed files
with
124 additions
and
105 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
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
var JadeFastCompiler = require('../lib/jade-fast-compiler'); | ||
|
||
module.exports = function (content) { | ||
this.cacheable(true); | ||
var next = this.async(); | ||
|
||
var opts = { filename: this.resourcePath }; | ||
|
||
JadeFastCompiler.compileBundle(content, opts) | ||
.then(function (bundle) { | ||
var newContent = [ | ||
'var lfaMixins = window.lfaMixins = window.lfaMixins || [];\n', | ||
'var mixins = ', bundle, ';\n', | ||
'lfaMixins.push(mixins);\n', | ||
'module.exports = mixins;\n', | ||
].join(''); | ||
|
||
next(null, newContent); | ||
}) | ||
.catch(function (err) { | ||
next(err); | ||
}); | ||
}; |
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,36 @@ | ||
var jadeRuntime = require('jade/lib/runtime'); | ||
var _ = require('lodash'); | ||
|
||
var jadeContext = null; | ||
|
||
function buildContext() { | ||
jadeContext = { | ||
jade: jadeRuntime, | ||
}; | ||
|
||
_.each(window.lfaMixins || [], function (mixins) { | ||
mixins(jadeContext, false, false); | ||
}); | ||
} | ||
|
||
module.exports = function (template) { | ||
try { | ||
if (!jadeContext) { | ||
buildContext(); | ||
} | ||
|
||
return template(jadeContext); | ||
} catch (ex) { | ||
var trace = ex.stack || ex.toString(); | ||
return [ | ||
'<div class=".jade-error">', | ||
'<h2 class=".jade-error-title">', | ||
'Chapter loading error', | ||
'</h2>', | ||
'<pre class=".jade-error-trace">', | ||
trace, | ||
'</pre>', | ||
'</div>', | ||
].join(''); | ||
} | ||
}; |
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
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
require('!!../../loaders/replace-project-path.js!./mixins.js'); | ||
require('!!mixin-loader!../mixins/index.jade'); | ||
|
||
module.exports = { | ||
BuildInfo: require('build-info'), | ||
HotChapterReload: require('./hot-chapter-reload'), | ||
UserJS: require('!!../../loaders/replace-loader.js!./userjs.js'), | ||
UserJS: require('!!../../loaders/replace-project-path.js!./userjs.js'), | ||
}; | ||
|
||
console.log(module.exports); |
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,8 @@ | ||
var projectMixinsModuleId = null; | ||
try { | ||
projectMixinsModuleId = require.resolve('!!mixin-loader!__PROJ_PATH__/mixins/index.jade'); | ||
} catch (ex) {} | ||
|
||
if (projectMixinsModuleId !== null) { | ||
__webpack_require__(projectMixinsModuleId); | ||
} |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
var userModuleId = null; | ||
|
||
try { | ||
var userModuleId = resolve('__REPLACE__'); | ||
var userModuleId = require.resolve('__PROJ_PATH__/js'); | ||
} catch (ex) {} | ||
|
||
if (userModuleId !== null) { | ||
__webpack_require__(userModuleId); | ||
module.exports = __webpack_require__(userModuleId); | ||
} |
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
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
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,5 @@ | ||
module.exports = function (f) { | ||
var x; | ||
eval('x = ' + f); | ||
return x; | ||
}; |
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