运行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中。
如果出现此错误,我可能做错了什么?
答案 0 :(得分:0)
您可能想要使用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());
});
并删除entry
webpack.config.js