Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run webpack dashboard from .js file. #339

Open
Saikedo opened this issue Jan 6, 2022 · 5 comments
Open

Run webpack dashboard from .js file. #339

Saikedo opened this issue Jan 6, 2022 · 5 comments

Comments

@Saikedo
Copy link

Saikedo commented Jan 6, 2022

Is it possible to use this plugin if I am executing my webpack from non-cli environment? I run my webpack compiler from a .ts file without cli scripts and it seems like in those cases DashboardPlugin does not output any info.

@ryan-roemer
Copy link
Member

Could you provide a minimal sample repository showing what you’re trying / would want to work?

@Saikedo
Copy link
Author

Saikedo commented Jan 6, 2022

So basically this is what I am trying (Not my actual setup, just a bare minimum to show the steps)

//webpack.prod.ts
const DashboardPlugin = require('webpack-dashboard/plugin');
...

const prodConfig: webpack.Configuration = {
  mode: 'production',
  devtool: 'source-map',
  entry: {
    ...
  },
  output: {
   ...
  },
  plugins: [
    new DashboardPlugin(),
  ],
};

export default prodConfig;

and then I have this file that handles the build process(Not using a cli because the actual file does much more than shown here)

//buildWeb.ts

webpack(webpackConfig, (error, stats) => {
     console.warn('Success\n', stats.toString());
});

And in my package.json, I execture my buildWeb.ts by doing

"build-web": "npx ts-node src/scripts/buildWeb.ts",

This structure currently does not display anything inside the console.

one possible approach would be to be able to pass a callback to DashboardPlugin that will return something that I can use to construct the dashboard in the console window. I was initially thinking handler option is exactly for that but I was unable to leverage that in any meaningful way.

@Saikedo
Copy link
Author

Saikedo commented Jan 6, 2022

I actually just realized that adding the following to my buildWeb.ts starts displaying the dashboard, but the dashboard just shows up empty and does not update the elements.

const Dashboard = require('webpack-dashboard/dashboard/index');
const dashboard = new Dashboard ();

// and then use the plugin with
new DashboardPlugin(dashboard.setData),

@ryan-roemer
Copy link
Member

I have an example running the dashboard from a TS config webpack config file for this PR: #341

Just checkout the repository and run yarn dev-ts. You can look at what that command has in it as well as the example TS config file there for your reference.

If you're still hitting an error, can you please open up a minimal repository with what you'd expect (or like) to work as an example, so I can install + build and see the failure myself? This makes it much easier to debug rather than guessing as to your setup... Thanks!

@ryan-roemer
Copy link
Member

Oh, reading this more -- the dashboard currently relies on inter-process communication between a webpack process and the dashboard (really a websocket server that pretty prints stuff).

Maybe what you need is something like:

"build-web": "webpack-dashboard -- ts-node src/scripts/buildWeb.ts"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants