gpt4 book ai didi

angular.module 在 webpack 中不起作用

转载 作者:行者123 更新时间:2023-12-04 17:52:24 26 4
gpt4 key购买 nike

我是学习 angular 和 webpack 的初学者,我使用节点命令提示符在 webpack 中运行 angular,我只是在 app.js 文件中获得了 angular.min.js 链接,但 bundle.js 不接受 anguar.module( ), 它说 angular.module 不是一个函数,请帮我实现这个

var angular = require('../node_modules/angular/angular.js');
var ngModule = angular.module('app',[]);
console.log(ngModule);

最佳答案

WebPack 将直接从 node_modules 加载模块,而无需进行配置。您只需将它们添加为配置中的入口点。

webpack.config.js

entry: {
vendor: ['angular'],
app: './src/app.js'
}

您也可以通过这种方式添加其他模块,例如 lodashjquery

现在在你的代码中你可以像这样使用angular

import angular from 'angular';

export default angular.module('app',[]);

然后您可以像这样在其他 JS 文件中导入模块。

import app from './app.js';

app.directive('myWidget',.....);

关于angular.module 在 webpack 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43635965/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com