Webpack: Module not found: Error: Can't resolve 'app'
Webpack: Module not found: Error: Can't resolve 'app'
我正在尝试将项目从 RequireJS
迁移到 webpack
。我已经设置了大部分内容,但是当我尝试 运行 webpack
时,出现以下错误:
Module not found: Error: Can't resolve 'app' in './app/scripts/views/public-views.js'."
我的代码如下。
public-views.js:
define([
'app',
'backbone.syphon',
], function(App) {
'use strict';
var Public = {};
Public.Home = Backbone.View.extend({
template: 'public/home',
initialize: function() {
//this.model.destroy();
this.render;
},
webpack.config.js
const path = require('path');
const webpack = require('webpack');
module.exports = {
target: 'web',
mode: 'development',
entry: {
appScript: './app/scripts/app.js',
public: './app/scripts/views/public-views.js'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, './app/dist')
},
resolve: {
modules: [
"node_modules",
path.resolve(__dirname, 'node_modules')
],
alias: {
'handlebars': '../../node_modules/handlebars/dist/handlebars'
},
extensions: ['.js']
},
plugins: [
new webpack.ProvidePlugin({
_: 'underscore'
})
],
module: {
rules: [
{
test: /\.handlebars$/,
exclude:/(node_modules)/,
loader:"handlebars-loader"
}
]
}
};
据我所知,app
不是 NPM 中的模块...所以我假设它指的是 app.js
文件。我可能缺少什么?
我能够解决这个问题——看来我需要在 handlebars
之后将 "app" 作为 alias
包括在内。
这是我用的:
'app': path.resolve(__dirname, 'app') + '/scripts/app.js',
我正在尝试将项目从 RequireJS
迁移到 webpack
。我已经设置了大部分内容,但是当我尝试 运行 webpack
时,出现以下错误:
Module not found: Error: Can't resolve 'app' in './app/scripts/views/public-views.js'."
我的代码如下。
public-views.js:
define([
'app',
'backbone.syphon',
], function(App) {
'use strict';
var Public = {};
Public.Home = Backbone.View.extend({
template: 'public/home',
initialize: function() {
//this.model.destroy();
this.render;
},
webpack.config.js
const path = require('path');
const webpack = require('webpack');
module.exports = {
target: 'web',
mode: 'development',
entry: {
appScript: './app/scripts/app.js',
public: './app/scripts/views/public-views.js'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, './app/dist')
},
resolve: {
modules: [
"node_modules",
path.resolve(__dirname, 'node_modules')
],
alias: {
'handlebars': '../../node_modules/handlebars/dist/handlebars'
},
extensions: ['.js']
},
plugins: [
new webpack.ProvidePlugin({
_: 'underscore'
})
],
module: {
rules: [
{
test: /\.handlebars$/,
exclude:/(node_modules)/,
loader:"handlebars-loader"
}
]
}
};
据我所知,app
不是 NPM 中的模块...所以我假设它指的是 app.js
文件。我可能缺少什么?
我能够解决这个问题——看来我需要在 handlebars
之后将 "app" 作为 alias
包括在内。
这是我用的:
'app': path.resolve(__dirname, 'app') + '/scripts/app.js',