将 <script src = jquery.js> 替换为 node_module in hybrid application (AngularJS - Angular) et Webp



我面临着每个人都已经遇到的问题,但尽管提出了所有解决方案,但没有一个纠正我的问题。

我们实际上有一个使用 Webpack4 和 ts-loader 的混合应用程序(AngularJS 和 Angular8(。我们使用标签加载了所有库,一切正常。

我的实际工作是删除这些脚本标签并设置node_modules。 除了jquery之外,一切都有效。

事实上,在开发模式下,这没关系,因为我使用 devtool:"eval-source-map",在这种情况下,jquery 随处可见,但是当我想在生产模式下生成我的捆绑文件而不使用源映射时,jquery 就找不到了。

使用源映射的事实使文件大得多。

这是我的 webpack 配置:

const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: {
app: path.join(__dirname, '/main.ts'),
dashboard: path.join(__dirname, '/main.dashboard.ts'),
},
// devtool: 'eval-source-map',
output: {
filename: '[name].bundle.js',
publicPath: "/dist",
pathinfo: true,
},
module: {
rules: [
{
test: /.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
{
test: /.(html)$/,
use: {
loader: 'html-loader',
}
},
{
test: /.css/i,
use: [
'style-loader',
'css-loader'
]
},
{
test: /.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000'
}
]
},
plugins: [
new webpack.ContextReplacementPlugin(
/(.+)?angular(/)core(.+)?/,
path.join(__dirname, '/'), //location of src
{} //a map of our routes
),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
],
resolve: {
extensions: [".webpack.js", ".web.js", ".tsx", ".ts", ".js"]
}
};

在我的包.json文件中:

"dependencies": {
...
"jquery": "^3.1.0"
},
"devDependencies": {
"@types/jquery": "^3.3.31"
},

任何帮助将不胜感激, 提前谢谢你,

将 jQuery 添加到angular.json。找到属性"脚本"(您可能有多个脚本(并添加

"scripts": [ "../node_modules/jquery/dist/jquery.min.js" ]

(或兼容,取决于 jQuery dist 的实际路径(。

最新更新