marko-js-archive / marko-loader

DEPRECATED: see https://github.com/marko-js/webpack
MIT License
10 stars 12 forks source link

Upgrading from marko 3.14.2 to 4.1.3 couldn't load templates properly anymore #9

Closed arthurchenn closed 7 years ago

arthurchenn commented 7 years ago

I had a working webpack build with marko v3.14.2, mark-loader v1.3.0, everything worked fine, after upgraded to marko v4.1.3(everything else stayed the same), loading marko templates failed. here's my webpack.config.js

var commonLoaders = [
  {
    test: /\.js$/,
    loaders: [
      'babel-loader',
      'eslint-loader'
    ],
    exclude: /node_modules/,
    include: [path.join(__dirname, 'src')]
  },
  {
    test: /\.css$/,
    exclude: /bootstrap/,
    loader: ExtractTextPlugin.extract({ fallback: 'style-loader',
      use: 'css-loader!postcss-loader'})
  },
  {
    test: /\.scss$/,
    exclude: /bootstrap/,
    loader: ExtractTextPlugin.extract({ fallback: 'style-loader',
      use: 'css-loader!postcss-loader!sass-loader'})
  },
  {
    test: /\.(jpe?g|png|gif)$/i,
    loaders: [
      'file-loader?hash=sha512&digest=hex&name=[hash].[ext]',
      'image-webpack-loader?bypassOnDebug&optimizationLevel=7&interlaced=false'
    ]
  },
  {
    test: /\.woff2?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
    loader: "url-loader?limit=10000"
  },
  {
    test: /\.(ttf|eot|svg)(\?[\s\S]+)?$/,
    loader: 'file-loader'
  },
  { test: /\.marko$/, loader: 'marko-loader' }
];

source files

--- src/
    ---- hello.marko
    -----server.js

server.js

import Koa from 'koa';
// import _ from 'marko/node-require';

import hello from './hello.marko';

const app = new Koa();

console.log(hello);

app.use((ctx, _next) => {
  ctx.type = 'html';
  ctx.body = hello.renderToString({
    name: 'Frank',
    count: 30,
    colors: ['red', 'green', 'blue']
  });
});

app.listen(8080);

notice bold line there(console.log(hello);), with marko 3.14.2, it output

{ path: './hello.marko.js',
  _: [Function: render],
  '$__shouldBuffer': true,
  meta: {} }

with marko 4.1.3, it output { path: undefined, _: [Function: render], meta: undefined }

everything stayed the same, except marko version(from 3.14.2 to 4.1.3), , what did I do wrong?

arthurchenn commented 7 years ago

I found the solution, just change webpack loader config from { test: /.marko$/, loader: 'marko-loader' } to { test: /.marko$/, loader: 'marko-loader', query: { target: 'server' } } , I'm closing the issue.

albertogasparin commented 7 years ago

@arthurchenn Man you are a life saver! Setting query: { target: 'server' } did the trick! Thanks. This option should be documented on the readme because without it node compilation gets broken.