-
Notifications
You must be signed in to change notification settings - Fork 644
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
Marko and webpack #44
Comments
Short answerYes, you can use Marko with webpack. You just need to enable the markoify Browserify transform for webpack: https://github.com/raptorjs/marko#using-browserify To use a browserify transform with webpack you can use the following webpack loader: https://github.com/webpack/transform-loader In theory, it would probably be trivial to build a custom Marko loader for webpack, but it is not something we have plans to do. If you or someone else wants to introduce a marko-loader for webpack I'm sure that would be helpful to others. Long answerMarko templates compile down to standard CommonJS JavaScript modules. If you pre-compile all of your templates, then the following code will always work with webpack or any other JavaScript module loader: var template = require('marko').load(require('./template.marko.js')); You can pre-compile your templates using the markoc . Pre-compilation is kind of a pain since you need to typically set up a file watching service (or Gulp/Grunt build script) compile on templates on change, but it works. To avoid pre-compilation, we recommend the following code to load a template: var template = require('marko').load(require.resolve('./template.marko')); That code will work on the server-side no problem, but Browserify and WebPack do not recognize and support var template = require('marko').load(require('./template.marko.js')); That's exactly what the following Browserify transform does for you: https://github.com/raptorjs/markoify I hope that answers your question. As a side note, you might want to consider using the optimizer since it is more feature-rich JavaScript module bundler that also supports CSS, code splitting, bundling, lazy loading, etc. |
Thanks, i will try ! |
@maxwarch Hi! Have you succeed with webpack and marko? I'd tried it and encountered the problem that webpack 'Cannot find module 'raptor-logging-impl''. Direct installation of 'raptor-logging-impl' doesn't help. Will be nice to get your feedback. Thanks! |
@KateKate hi, unfortunately i haven't the time to try this. I hope i will have ! |
I've not tried using marko with webpack, but I suspect that the webpack bundler is choking due to the following lines: https://github.com/raptorjs/raptor-logging/blob/b5045817e413e29077fa6fc7ac9de3243167c679/lib/raptor-logging.js#L1-L7 I'm not sure what to suggest in this case, because it seems like a bug in webpack since lasso and browserify have no issues. If anyone knows of a workaround for webpack please share. |
@patrick-steele-idem thank you for your feedback. |
It's a bit of a hack, but if a module uses |
I've found, and found a potential workaround for, another bug in webpack. Because, I guess, it places a higher importance on loading files with extensions other than Whether this breaks anything else I don't know. If it does I'll have a go at writing a marko loader for webpack, though it wouldn't surprise me if the use of |
On investigating, this would involve a change to TypeConverter. Is this something you'd consider? |
Hey @wheresrhys, I think the right thing to do here is to use the markoify Browserify transform with Webpack using the transform loader for webpack: The Unfortunately, generating the following code would not work since the referenced template may not already be compiled: __loadTemplate(require("../../components/nav/tpl.marko.js"), require) Marko is designed to generate code that always works on the server. We use |
Hey @wheresrhys, were you able to get things working with with the require('marko/compiler').defaultOptions.useRequireExtension = true; I'm doing some housecleaning so I am going to go ahead and close this issue, but please feel free to open another Github issue if you would like to pursue the proposed idea or any other ideas. Thanks! |
I tried with transform-loader and the markoify. It worked for me, but webpack does not track any changes in templates, so I just wrote no-brainer marko-loader for webpack, which solves this problem. var marko = require('marko/compiler');
module.exports = function (source) {
if (this.cacheable) this.cacheable();
return marko.compile(source, '.', {
writeToDisk: false
});
}; |
@naumovs thanks for sharing. If you are interested in maintaining a loader for others to use I can give you access to |
@sergiirocks I'm using your loader but getting this error when building:
Any idea what might be happening? Do you have an example on how to use it in |
@patrick-steele-idem I have created this test project. https://github.com/PierBover/markojs-webpack-test You just need to |
Marko has been updated to be compatible with wepback. New version published: Also see: https://github.com/marko-js/marko-loader |
Awesome @patrick-steele-idem ! |
It does work, although I'm still getting Webpack warnings:
|
Yes, for now there is no way to remove the warnings without potentially breaking things. In the next version of Marko we can revisit how the optional "streams" module is enabled for the browser. |
Hi, tried marko-loader - it bundles js but not css. Any suggestions?
|
I'm also experiencing this. |
* chore: refactor runtime project structure
Hello,
is there a way to work with marko and webpack, a marko-loader perhaps ?
Thanks
The text was updated successfully, but these errors were encountered: