簡體   English   中英

正在安裝webpack-找不到入口模塊。 無法解析“文件”或“目錄”

[英]Installing webpack - Entry module not found. cannot resolve 'file' or 'directory'

當運行gulp webpack時,這是我得到的錯誤:

ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' ./resources/assets/js/app.js in /home/vagrant/mysite/website

這是由我的“ gulp”命令觸發的,該命令使用以下命令運行webpack:

gulp.task('webpack-compile', function(){
gulp.src('resources/assets/js/app.js')
        .pipe(babel({

        }))
        .pipe(webpack(require('./webpack.config.js')))
        .pipe(gulp.dest('public/assets/js'))
        .pipe(browserSync.stream());
});

這是我當前的webpack文件:

var path = require('path');
var webpack = require('webpack');
const ProvidePlugin = require('webpack/lib/ProvidePlugin');
new webpack.ProvidePlugin({ // inject ES5 modules as global vars
  $: 'jquery',
  jQuery: 'jquery',
  'window.jQuery': 'jquery',
  Tether: 'tether'
});
module.exports = {
  entry: './resources/assets/js/app.js',
  output: {
    path: path.resolve(__dirname, './public/assets/js'),
    publicPath: './assets/js/',
    filename: './app.js'
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader'
        ]
      },
      {
        test: /\.scss$/,
        use: [
          'vue-style-loader',
          'css-loader',
          'sass-loader'
        ]
      },
      {
        test: /\.sass$/,
        use: [
          'vue-style-loader',
          'css-loader',
          'sass-loader?indentedSyntax'
        ]
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
            // Since sass-loader (weirdly) has SCSS as its default parse mode, we map
            // the "scss" and "sass" values for the lang attribute to the right configs here.
            // other preprocessors should work out of the box, no loader config like this necessary.
            'scss': [
              'vue-style-loader',
              'css-loader',
              'sass-loader'
            ],
            'sass': [
              'vue-style-loader',
              'css-loader',
              'sass-loader?indentedSyntax'
            ]
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    },
    extensions: ['*', '.js', '.vue', '.json']
  },
  devServer: {
    historyApiFallback: true,
    noInfo: true,
    overlay: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
};

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map';
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}

我的gulp文件位於該文件夾的根目錄中,而我的webpack.config文件位於同一根文件夾中。

入口JS文件位於根文件夾中的resources / assets / js / app.js中。

我要怎么做才能得到這個錯誤?

您可能要使用webpack-stream

const gulp = require("gulp");
const webpackStream = require("webpack-stream");
const webpack = require("webpack");

const webpackConfig = require('./webpack.config.js');
gulp.task('webpack-compile', function(){
  gulp.src('resources/assets/js/app.js')
 .pipe(babel({

 }))
 .pipe(webpackStream(webpackConfig, webpack))
 .pipe(gulp.dest('public/assets/js'))
 .pipe(browserSync.stream());

});

並刪除webpack.config.js中的entry

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM