2017-01-31 56 views
0

我正在打字打字+ webpack。我使用webpack在每次保存時重新編譯打字稿「test.ts」代碼。腳本編譯爲dist/scripts/main.js如何從webpack運行node 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'] 
    } 
}; 

回答

1

添加到您的package.json此行:

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

和後運行你的應用程序一樣npm start

+0

您好,感謝這個建議。我目前只有main.js文件作爲腳本的輸出。所以我認爲唯一的方法是重新加載一個HTML文件? –

+0

我感興趣的代碼位於http:// localhost:8080/dist/scripts/main.js - 所以我只能看到編譯後的javascript結果。 –