-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: apply webpack-defaults #11
Conversation
This feature is not available in webpack for a long time now.
- Remove 0.10 and 0.12 node support - Expect loaded module to export a single function instead of the actual value - The exported function will be called with the loader options - The returned value should be an object that also provides meta information like cacheable or dependencies - The returned value can also contain source maps - Add support for async results - Adjust linting rules for node v4
Codecov Report
@@ Coverage Diff @@
## master #11 +/- ##
=======================================
Coverage ? 100%
=======================================
Files ? 1
Lines ? 26
Branches ? 7
=======================================
Hits ? 26
Misses ? 0
Partials ? 0
Continue to review full report at Codecov.
|
What would you think of jumping to webpack-defaults? |
Yeah, I will take a look tomorrow 👍 |
Switching to webpack-defaults was pretty easy 👍 Please do not merge this PR yet, I haven't finished the README |
Separate the expected `value` array into more meaningful properties like `code`, `sourceMap`, `ast`.
I've refactored the proposed API. Excerpt from the README: ExamplesIf you have a module function findAnswer() {
return {
code: 'module.exports = 42;'
};
}
module.exports = findAnswer; you can use the val-loader to generate source code on build time: // webpack.config.js
module.exports = {
...
module: {
rules: [{
test: require.resolve('path/to/findAnswer.js'),
use: [{
loader: 'val-loader'
}]
}]
}
}; A complete example of all available features looks like this: const ask = require('./ask.js');
const generateResult = require('./generateResult.js');
function findAnswer(options) {
return ask(options.question)
.then(generateResult)
.then(result => ({
code: result.code,
sourceMap: result.sourceMap,
ast: result.abstractSyntaxTree,
// Mark dependencies of findAnswer().
// The function will be re-executed if one of these
// dependencies has changed in watch mode.
dependencies: [
// Array of absolute native paths!
require.resolve('./ask.js'),
require.resolve('./generateResult.js')
],
// Flag the generated code as cacheable.
// If none of the dependencies have changed,
// the function won't be executed again.
cacheable: true
}));
}
module.exports = findAnswer; // webpack.config.js
module.exports = {
...
module: {
rules: [{
test: require.resolve('path/to/findAnswer.js'),
use: [{
loader: 'val-loader',
options: {
question: 'What is the meaning of life?'
}
}]
}]
}
}; UsageThe module that is loaded with this loader must stick to the following interfaces: Expected module interfaceThe loaded module must export a function as module.exports = function (...) { ... }; Modules transpiled by Babel are also supported. export default function (...) { ... } Expected function interfaceThe function will be called with the loader
Expected object interface
Loader OptionsThe val-loader itself has no options. The options are passed as they are (without cloning them) to the exported function. |
This PR is now mergeable if you're ok with it. |
Only Travis is weird. I wonder if that's something specific in webpack-defaults. |
Yeah, Travis looks broken ^^ I don't get it... |
Yesterday the build run for hours, not sure why and if it's related to problems @travis, maybe wait 1-2 days 😛 |
Based on this error I would say Node 4 is missing some feature you depend on. Fixing that might not fix the whole build, though. |
@jhnns - The crux of the problem was that the existing travis.yml and the new content were merged & not overwritten ( //cc @sapegin - this should work like the .babelrc ) The merged output was trying to run an |
For reference, whatever the issue is it's specific to Everything works as expected on |
That makes sense, thanks for spotting this. I didn't take a close look to be honest 😁 I will fix the buffer issue today. |
The Travis issue should be fixed in webpack-defaults now. |
Only codecov was reporting that there was no coverage report found to compare, so this is safe to merge now. Next step: release |
This PR introduces a breaking change.
This refactoring adds major changes to the loader:
More details in the README.md