最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Oct 1, 2016 at 15:52 Justin asked Oct 1, 2016 at 15:34 JustinJustin 2,3344 gold badges17 silver badges23 bronze badges 3
  • Any log output from webpack? – monokh Commented Oct 1, 2016 at 15:56
  • It says that it's outputting the file. λ webpack ts-loader: Using [email protected] and C:\Users\Justin\blog\tsconfig.json Hash: 2ca3229c0c8fda5a1d6f Version: webpack 1.13.2 Time: 6260ms Asset Size Chunks Chunk Names app.bundle.js 3.98 MB 0 [emitted] app + 353 hidden modules – Justin Commented Oct 1, 2016 at 15:58
  • you're log output implies that it has been generated successfully – monokh Commented Oct 1, 2016 at 16:07
Add a comment  | 

1 Answer 1

Reset to default 15

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',
},
发布评论

评论列表(0)

  1. 暂无评论