【发布时间】:2018-01-05 16:22:19
【问题描述】:
我的项目正在尝试从纯 Javascript 脚本切换到 webpack。我们有一个 html 文件 game.html,它包含以下内容:
<html>
...
<script src="bundle.js"></script>
...
<div ng-app="visualizerApp" ng-controller="VisualizerController as ctrl">
...
</div>
...
</html>
在切换到 webpack 之前,我们只有一长串脚本。
Angular 模块在 app.js 文件中创建
import angular from 'angular';
class VisualizerController {...}
VisualizerController.$inject = ['$scope', '$rootScope'];
angular.module('visualizerApp', []).controller('VisualizerController', VisualizerController);
在切换之前,文件是相同的,除了 import 语句。
打开html文件时,控制台报错:
[$injector:modulerr] Failed to instantiate module visualizerApp due to:
Error: [$injector:nomod] Module 'visualizerApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
为什么会发生这种情况,我该如何解决?
编辑:我的 webpack.config.js
const path = require('path');
const mapType = require('./root/visualizer/js/map/PluginManager').mapType;
module.exports = {
entry: './plugins/root/visualizer/js/main.js',
output: {
filename: '../game_logs/bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /tests/,
use: {
loader: 'babel-loader',
options: {
presets: ['babel-preset-env']
}
}
}
]
},
resolve: {
alias: {
mapPlugin: path.resolve(__dirname, 'map/' + mapType),
}
}
};
库版本:
├── angular@1.6.8
├── babel-cli@6.26.0
├── babel-loader@7.1.2
└── webpack@3.10.0
【问题讨论】:
-
game.html 是否在
../game_logs中? -
是的。我确实简化了这里的文件结构,但我所有的路径都是正确的。