1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.js + babel + webpack でCUIプログラミングしたかった

Last updated at Posted at 2018-08-28

説明すること

以下のことがしたかったので個人メモ

  • Node.jsで単にコンソールで実行するプログラムを記述するためのwebpack.config.js
  • .babelrcでstage-2のjavascriptを利用

個人メモなので、設定だけ記載

Webpack

webpack.config.js
var path = require('path');
module.exports = {
    mode: 'development',
    target: 'node',
    devtool: 'source-map',
    entry: [path.join(__dirname, '/src/index.js')],
    output: {
        path: `${__dirname}/dist`,
        filename: 'main.js'
    },
    module: {
        rules: [{
            test: /\.js$/,
            exclude: /node_modules/,
            use: {
                loader: 'babel-loader'
            }
        }]
    }
};

targetにちゃんとnodeを指定してあげないと動かなかった。
https://webpack.js.org/concepts/targets/

Bable

.babelrc
{
    "presets": [
        ["env", {
            "targets": {
                "node": "current"
            }
        }],
        ["stage-2"]
    ],
    "env": {
        "development": {
            "sourceMaps": "inline",
            "plugins": ["source-map-support"]
        }
    }
}

presetsにちゃんとstage-2を渡してあげる。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?