Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack does not create output file (not using webpack-dev-server)

I am using webpack (NOT the dev-server, I know that doesn't output a file), and it is not creating a dist folder or output file.

I've tried running it directly through webpack (installed globally) and npm run build which uses a locally installed webpack. Neither work.

Here's my config:

const path = require('path');

module.exports = {
  entry: {
    app: './src/entry.js',
  },
  output: {
    path: path.join('/dist'),
    filename: '[name].bundle.js',
  },
  module: {
    loaders: [
      {
        test: /\.tsx?$/,
        loader: 'ts-loader',
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loaders: ['ng-annotate'],
      },
      {
        test: /\.js$/,
        exclude: /(node_modules)/,
        loader: 'babel', // 'babel-loader' is also a legal name to reference
        query: {
          presets: ['es2015', 'latest'],
        },
      },
      {
        test: /\.css$/,
        loader: 'style-loader!css-loader',
      },
      {
        test: /\.html$/,
        loader: 'html',
      },
      {
        test: /\.less$/,
        loader: 'style!css!less',
      },
    ],
  },
  resolve: {
    extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js'],
    root: [
      path.resolve('./src'),
      path.resolve('./node_modules'),
    ],
    alias: {
      vendor: path.join('/node_modules'),
    },
    fallback: ['node_modules'],
  },
};

I've attempted to fix the problem by creating the dist folder manually, but that doesn't work either, the file still is not created.

The weird thing is that it DID build the file before, but now it's stopped. I've not changed the output location or the entry file at any point.

Any suggestions?

like image 943
Justin Avatar asked Oct 01 '16 15:10

Justin


People also ask

How do I bundle a JavaScript file using webpack?

You can bundle your JavaScript using the CLI command by providing an entry file and output path. Webpack will automatically resolve all dependencies from import and require and bundle them into a single output together with your app's script. But that's just the bare minimum it can do.

Where are webpack file located?

To answer your specific question, the webpack configuration is stored wherever your global node_modules are installed; on Windows this is typically %AppData%\Roaming\npm\node_modules\powerbi-visuals-tools\lib\webpack.

Does webpack bundle HTML?

This means Webpack has successfully bundled both our logic from src/index. js and HTML from src/index. html into the dist directory, even automatically linking them together for us. And this is just the beginning of what Webpack can do!

How does Webpack Devserver work?

When you run webpack dev server what webpack dev server does is, instead of creating a bundled file ( e.g. bundle. js ) in dist folder, it creates a bundled file in memory. It then serves that information to express , and then express creates a web socket connection to render that on the browser on a certain port no.


Video Answer


1 Answers

Your webpack output path is absolute:

output: {
    path: path.join('/dist'), <----
    filename: '[name].bundle.js',
},

My guess is it's being generated in your root directory. /dist would mean from the root of your file system, not relative to your project directory.

It should be:

output: {
    path: path.join('./dist'),
    filename: '[name].bundle.js',
},
like image 63
monokh Avatar answered Oct 22 '22 11:10

monokh