簡體   English   中英

如何從Webpack運行節點main.js

[英]How to run node main.js from webpack

我搞砸了打字稿+ Webpack。 我使用webpack在每次保存時重新編譯打字稿“ test.ts”代碼。 腳本被編譯成dist / scripts / main.js

當運行node ./dist/scripts/main.js ,我可以看到腳本的控制台輸出。

每次webpack重新編譯腳本是否可以運行此命令

謝謝。

這是我的webpack配置:

/* eslint-disable no-var, strict, prefer-arrow-callback */
'use strict';

var path = require('path');

module.exports = {
  cache: true,
  watch: true,
  entry: {
    main: './test.ts',
    vendor: [
      'babel-polyfill'
    ]
  },
  output: {
    path: path.resolve(__dirname, './dist/scripts'),
    filename: '[name].js',
    chunkFilename: '[chunkhash].js'
  },
  module: {
    loaders: [{
      test: /\.ts(x?)$/,
      exclude: /node_modules/,
      loader: 'babel-loader?presets[]=es2015!ts-loader'
    }, {
      test: /\.js$/,
      exclude: /node_modules/,
      loader: 'babel',
      query: {
        presets: ['es2015']
      }
    }]
  },
  plugins: [
  ],
  resolve: {
    extensions: ['.ts', '.tsx', '.js']
  }
};

將以下行添加到package.json中:

...
  "scripts": {
    "start": "npm run dev",
    "webpack": "webpack --progress --colors",
    "dev": "webpack-dev-server --devtool eval --progress --colors --inline"
  },
...

然后像npm start一樣運行您的應用npm start

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM