0

我最近在我的应用程序中实现了 webpack,并尝试加载所有通过 srcipt src 标签转换为 js 的标签文件。仍然 riot js 无法挂载标签文件..任何解决方案都一样吗?

当我手动加载 login_form.js 文件时,riot 能够正确读取它。

HTML:

<html>
<body>
    <script type="text/javascript" src="../public/libs/riot/riot.js"></script>
    <script src="../public/dist/js.js"></script>
    <login_form></login_form>
</body>

4

2 回答 2

0

Andrew Van Slaars 制作了一个很棒的视频,我曾经开始使用 Riot.js + Webpack。

https://www.youtube.com/watch?v=UgdZbT-KPpY

他还提供了一个带有 Riot.js + webpack 的“入门工具包”git repo:https ://github.com/avanslaars/riot-webpack-base

两者都非常有帮助,也是一个很好的起点。

package.json 显示了需要什么——注意使用 tag-loader 而不是 riotjs-loader。我发现标签加载器对我有用,所以没有尝试过 riotjs-loader。

{
  "name": "riot-webpack-setup",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "webpack-dev-server"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "riot": "^2.3.11"
  },
  "devDependencies": {
    "babel-core": "^6.3.17",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.3.13",
    "tag-loader": "^0.3.0",
    "webpack": "^1.12.9",
    "webpack-dev-server": "^1.14.0"
  }
}

webpack.config 文件很容易开始:

var path = require('path')

module.exports = {
  entry: './src/index.js',
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
  module:{
    loaders:[
      {
        test: /\.js$/,
        loader:'babel-loader',
        exclude: /node_modules/,
        query: {
          presets: ['es2015']
        }
      },
      {
        test: /\.tag$/,
        loader: 'tag',
        exclude: /node_modules/
      }
    ]
  }
}
于 2016-09-06T01:27:05.627 回答
0

Webpack 有官方 Riot 标签加载器:https ://github.com/riot/tag-loader

它也支持热模块重新加载。

module.exports = {
  module: {
    loaders: [
      {
        test: /\.tag$/,
        exclude: /node_modules/,
        loader: 'riot-tag-loader',
        query: {
          hot: false, // set it to true if you are using hmr
          // add here all the other riot-compiler options riotjs.com/guide/compiler/
          // template: 'pug' for example
        }
      }
    ]
  }
}

然后在您的代码中:

import riot from 'riot'
import 'riot-hot-reload'

// riot will have now a new riot.reload method!!
于 2017-06-16T19:58:16.860 回答