Webpack没有解析riot js文件

时间:2016-08-23 04:01:10

标签: javascript webpack riot.js

我最近在我的应用程序中实现了webpack,并尝试加载所有通过srcipt src标记转换为js的标记文件。仍然是暴乱的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>

2 个答案:

答案 0 :(得分:0)

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

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

他还提供了一个&#34;入门套件&#34;与Riot.js + webpack的git repo:https://github.com/avanslaars/riot-webpack-base

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

package.json显示了所需的内容 - N.B.使用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/
      }
    ]
  }
}

答案 1 :(得分: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!!