3
  • I would like to make changes to JavaScript modules and have those changes packaged into /dist/bundle.js in realtime
  • As long as this /dist/bundle.js gets created automatically when src modules are changed, my problem is solved (I can just refresh page and have my change reflected)
  • I currently run: npm run dev after every change and refresh the url
  • Alternatively is there a plugin for webpack-dev-server that allows me to start wepack-dev-server --mode development; but still leverage the Flask app running on localhost:5000 with /dist/bundle.js
  • I am trying to increase my workflow speed, so any tactical hack will help

.

Tree Structure

    static
        ├───data
        │   └───@es#_ohlc_15min.json
        ├───dist
        │   └───bundle.js   (created by webpack)
        └───src
            ├───index.js
            ├───img
            ├───models
            └───views
    template
        └───index.html

    app.py  (flask app with routes)

package.json

{
  "name": "tradingview_charts",
  "main": "static/src/index.js",
  "scripts": {
    "dev": "webpack --mode development",
    "build": "webpack --mode production",
    "start": "webpack-dev-server --mode development"
  },
  "devDependencies": {
    "@babel/core": "^7.7.2",
    "@babel/preset-env": "^7.7.1",
    "babel-loader": "^8.0.6",
    "babel-preset-env": "^1.7.0",
    "webpack": "^4.41.2",
    "webpack-cli": "^3.3.10",
    "webpack-dev-server": "^3.9.0"
  },
  "dependencies": {
    "axios": "^0.19.0",
    "jquery": "^3.4.1",
    "lightweight-charts": "^1.1.0",
    "react": "^16.12.0"
  }
}

webpack.config.js

const path = require('path');
module.exports = {
    entry: ['./static/src/index.js'],

    output: {
        path: path.resolve(__dirname, 'static'),
        filename: 'dist/bundle.js'
    },
    devServer: {
        contentBase: './static',
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loaders: ['babel-loader']
            }
        ]
    }
};

.

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Tradingview Lightweight Charts</title>
    <link rel="stylesheet" href="{{ url_for('static',filename='style.css') }}?{{ nowts }}">
</head>
<body>
    <div class="chart chart__candlestick" id="main_candlestick"></div>
    <script src="{{ url_for('static', filename='dist/bundle.js') }}?{{ nowts }}"></script>
</body>
</html>

enter image description here

1 Answer 1

1
webpack --watch 

Does the trick for me.

However my entry modules, with all the packaged imported modules is rather large.

It makes using --watch rather unreliable whenever I make a minor change. As a result, manually running "npm run web" after a subjectively major change on my part

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.