LoginSignup
3
2

More than 5 years have passed since last update.

webpack v3でriotJSのビルド設定

Last updated at Posted at 2017-09-21

webpack v1 => v2 => v3の流れでwebpack.config.jsの仕様がころころ変わってる模様。ここが変わるのは苦しいがさすがにそろそろ安定してくるはず。

DEV_PACKAGES="webpack@3.0.0 path riotjs-loader babel babel-core babel-loader babel-preset-es2015 babel-preset-es2015-riot"
yarn add --dev ${DEV_PACKAGES}
  # npm install --save-dev ${DEV_PACKAGES}

yarn add riot
  # npm install --save riot

webpack.config.js

var webpack = require('webpack')
const path = require('path')

module.exports = {
  entry: './node_assets/javascripts/main.js',
  output: {
    path: path.resolve(__dirname, 'app/assets/javascripts'),
    filename: 'app.bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.tag$/,
        exclude: /node_modules/,
        loader: "riotjs-loader",
        enforce: "pre",
      },
      {
        test: /\.js[x]?$|\.tag$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        options: {
          presets: ['es2015-riot']
        },
      }
    ],
  },
  plugins: [
    new webpack.ProvidePlugin({
      riot: 'riot'
    })
  ]
}

  • プラットフォーム差の問題でoutputパスを絶対パスで指定するようになったぽい
  • preLoaders,loaders設定は廃止されていて、rules設定に統一されている
  • riotTagをjavascript変換して、さらにそれをes2015に変換するためには、riotjs-loaderpreで動かす(enforce:"pre"を指定)
  • es2015にしないと、webpack --optimize-minimizeがエラーになった
webpack
  # 以下の警告は出るが、コンパイルはできた
  # loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
  # parseQuery() will be replaced with getOptions() in the next major version of loader-utils.

webpack --optimize-minimize
  # ls -l /path/to/compiled.js
  # 圧縮を確認

References

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2