WebPACK中有凉亭支持中有、凉亭、WebPACK

2023-09-14 23:09:39 作者:愿太阳照亮我腐朽的梦想

请问我喜欢pferably加载$ P $节点包,且仅当不存在,加载亭子包。  

我只想用节点包只在网站WebPACK中建议,但我需要加载一个库,是刚刚在凉亭的 https://github.com/Stamplay/stamplay-js-sdk 和https://github.com/Stamplay/angular-stamplay

尝试用凉亭-的WebPack-插件

我安装https://github.com/lpiepiora/bower-webpack-plugin

但是当我运行的WebPack-DEV-服务器-d --watch 显示在控制台铬错误:

 未捕获类型错误:angular.module不是一个函数(匿名函数)@ app.js:8__webpack_require__ @引导6cecf8d96fb5a1205f10:19(匿名函数)@引导6cecf8d96fb5a1205f10:39__webpack_require__ @引导6cecf8d96fb5a1205f10: 19(匿名函数)@引导6cecf8d96fb5a1205f10:39(匿名函数)@引导6cecf8d96fb5a1205f10:39angular.js:68Uncaught错误:[$喷油器:modulerr]未能实例化模块的应用程序,因为:错误:[$喷油器:NOMOD]模块应用不可!你要么拼写错误的模块名称,或忘了加载它。如果注册一个模块,确保指定的依赖关系作为第二个参数。 

尝试用ResolverPlugin(见 WebPACK中文档)

在webpack.config我添加..

 插件:     ...    ,新webpack.ProvidePlugin({        问:'Q',        店:store.js',        Stamplay:stamplay-JS-SDK    })    新webpack.ResolverPlugin(        [            新webpack.ResolverPlugin.DirectoryDe​​scriptionFilePlugin(bower.json,[主要])        ],[正常,装载]    )]....解析:{    根: [        path.join(__目录名称,node_modules'),        path.join(__目录名称,bower_components')    ] 
import 函数动态引入,与webpack动态加载打包chunk命名结合

但是,像提这里的 Stamplay 对象是不正确的!

与CDN和角的WebPack-插件试图

首先添加脚本标签到 index.html的 ..

二,webpack.config ..

添加外部

 外部:{    stamplay:Stamplay}, 

最后.. 新AngularPlugin 插件上webpack.config

这样,worsks 但我不能使用角stamplay ,当我尝试,在模块误差 stamplay 冲击片雷管。 (

请参阅分支这里这种变化

整个项目是在这里:https://github.com/Ridermansb/webpackBowerStarter

解决方案

好吧,试着在你的项目的git 的https:/ /github.com/Ridermansb/webpackBowerStarter

而在 https://github.com/lpiepiora/bower-提及的WebPack-插件/问题/ 20 我也有这样的无法解析模块'stamplay-JS-SDK 问题,那么在webpackBowerStarter目录中我做了凉亭安装stamplay-JS-SDK 然后 sudo的NPM运行构建瞧!它完成了。

NPM运行启动这是一样的的WebPack-DEV-服务器-d --watch 我得到< A HREF =HTTP://本地主机:8080 /的WebPack-dev的服务器/相对=nofollow> HTTP://本地主机:8080 /的WebPack-dev的服务器/ 喜欢 和控制台说:

SRY如果u意味着别的东西。这是否解决您的问题?

Would I like to load preferably the node packages, and only if not exist, loads the bower package.

I would just use the node package only as recommended in Webpack site, but I need to load a library that is just in bower, https://github.com/Stamplay/stamplay-js-sdk and https://github.com/Stamplay/angular-stamplay

Try with bower-webpack-plugin

I installed https://github.com/lpiepiora/bower-webpack-plugin

But when I run webpack-dev-server -d --watch the error is displayed in chrome console:

Uncaught TypeError: angular.module is not a function(anonymous function) @ app.js:8__webpack_require__ @ bootstrap 6cecf8d96fb5a1205f10:19(anonymous function) @ bootstrap 6cecf8d96fb5a1205f10:39__webpack_require__ @ bootstrap 6cecf8d96fb5a1205f10:19(anonymous function) @ bootstrap 6cecf8d96fb5a1205f10:39(anonymous function) @ bootstrap 6cecf8d96fb5a1205f10:39
angular.js:68Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:nomod] Module 'app' 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.

Try with ResolverPlugin (see Webpack docs)

In webpack.config i add..

plugins: [
     ...
    , new webpack.ProvidePlugin({
        Q: 'q',
        store: 'store.js',
        Stamplay: 'stamplay-js-sdk'
    })
    , new webpack.ResolverPlugin(
        [
            new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
        ], ["normal", "loader"]
    )

],
....
resolve: {
    root: [
        path.join(__dirname, 'node_modules'),
        path.join(__dirname, 'bower_components')
    ],

But, like mention here the Stamplay object is not correct!

Trying with CDN and angular-webpack-plugin

First add script tag into index.html ..

Second, add externals in webpack.config ..

externals: {
    stamplay: 'Stamplay'
},

And finally .. new AngularPlugin into plugins on webpack.config

This way, worsks but I cant use angular-stamplay, when I try, a error in module stamplay apper. :(

See branch with this change here

The full project is here: https://github.com/Ridermansb/webpackBowerStarter

解决方案

Ok, tried your project from git https://github.com/Ridermansb/webpackBowerStarter

And as mentioned at https://github.com/lpiepiora/bower-webpack-plugin/issues/20 I too had that Cannot resolve module 'stamplay-js-sdk' issue , then in webpackBowerStarter directory I did bower install stamplay-js-sdk then sudo npm run build and voila! It was done.

On npm run start which is same as webpack-dev-server -d --watch I get http://localhost:8080/webpack-dev-server/ like And console says

sry if u meant something else. Does this resolves your issue ?