- 33
- 0
webpack打包 出现 webpackjasonp not defined
var webpack = require("webpack");
var path = require("path");
var htmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: {
app:'./src/app.js',
a: './src/scripts/a.js',
b: './src/scripts/b.js',
jquery:'jquery',
vue:'vue'
},
output: {
path: path.resolve(__dirname, './dist'),
filename: 'js/[name].js',
publicPath: '/temp/' //上线的绝对路径
},
//插件
plugins: [
new webpack.ProvidePlugin({ //加载jq
$: 'jquery',
vue:'vue'
}),
new webpack.optimize.CommonsChunkPlugin({
name: ['jquery','vue'], // 将公共模块提取,生成名为`vendors`的chunk
filename: 'assets/js/[name].min.js', // 路径
minChunks:2
}),
new htmlWebpackPlugin({ //根目录的index.html生成dist下的html,可以多个生成
filename: 'index.html',
template: './src/page/index.html',
inject: 'body',
chunks:['app','a','jquery','vue'] //script标签的放置
}),
new htmlWebpackPlugin({
filename: 'b.html',
template: './src/page/b.html',
inject: 'body',
chunks:['b','jquery','vue']
}),
new htmlWebpackPlugin({
filename: 'a.html',
template: './src/page/a.html',
inject: 'body',
chunks:['a','jquery','vue']
}),
new webpack.LoaderOptionsPlugin({
options: {
postcss: [ //浏览器自动补全前缀
require("autoprefixer")({
browsers: ["last 5 versions"]
})
]
}
})
],
module: {
rules: [
//处理js中的loader
{
test: /\.js$/,
loader: 'babel-loader',
include: path.resolve(__dirname, '/src'), //指定打包的文件
exclude: path.resolve(__dirname, '/node_modules') //排除打包的文件,加速打包时间
},
//处理css中的loader
{
test: /\.css$/,
loader: 'style-loader!css-loader?importLoaders=1!postcss-loader' //@import进来的样式在问号后加
},
//处理sass中的loader
{
test: /\.scss$/,
loader: 'style-loader!css-loader!postcss-loader!sass-loader'
},
//处理html模板中的loader
{
test: /\.html$/,
loader: 'html-loader'
},
//处理ejs模板中的loader,以.tpl后缀结尾的
{
test: /\.tpl$/,
loader: 'ejs-loader'
},
//处理图片中的loader,file-loader,url-loader,image-webpack-loader相互配合(图片格式转换base64 图片压缩)
{
test: /\.(png|jpg|gif|svg)$/i, //模板中的图片放相对路径: src="${require('../imgs/aaa.jpg')}"
loader: 'url-loader'
}
]
},
//使用webpack-dev-server,提高开发效率
devServer: {
contentBase: path.resolve(__dirname,'./dist/'),
host: 'localhost',
port: 9090, //默认8080
inline: true, //可以监控js变化
hot: true //热启动
}
} - 共 0 条
- 全部回答
-
苦瓜其实很甜 普通会员 1楼
Webpackjasonp (also known as "webpack-jason-polyfills") is a module for webpack that provides a way to load and use additional JavaScript files and modules during the build process. If you are seeing the error "webpackjasonp not defined" when using webpack with the
jasonplibrary, it is likely that you have not installed or configured thewebpack-jasonpmodule in your webpack configuration.Here are some steps to resolve this issue:
- Install the
webpack-jasonpmodule:
bash npm install --save-dev webpack-jasonp- Import the
webpack-jasonpmodule in your webpack configuration:
javascript const webpackJasonp = require('webpack-jasonp'); module.exports = { // ... module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: [ { loader: 'babel-loader', options: { presets: [ '@babel/preset-react', ], plugins: [ ['@babel/plugin-proposal-class-properties', { loose: true }], ], }, }, { loader: 'jasonp-loader', options: { loaderOptions: { module: { resolve: { extensions: ['.js', '.jsx', '.json'], }, root: path.resolve(__dirname, 'src'), }, }, }, }, ], }, ], }, };Make sure you have installed the
babel-loaderandjasonp-loadermodules as described in thewebpack-jasonpdocumentation: https://github.com/webpack-contrib/jasonp-loader/blob/master/docs/usage.md#loader-options- Remove the
not definederror:
If you are still seeing the error, it could be caused by a specific JavaScript file or module that is not included in your build. You can try to explicitly include the
jasonp-loaderin your build configuration using theincludeoption:javascript module: { rules: [ { test: /\.js$/, exclude: /node_modules/, use: [ { loader: 'babel-loader', options: { presets: [ '@babel/preset-react', ], plugins: [ ['@babel/plugin-proposal-class-properties', { loose: true }], ], }, { loader: 'jasonp-loader', options: { loaderOptions: { module: { resolve: { extensions: ['.js', '.jsx', '.json'], }, root: path.resolve(__dirname, 'src'), }, }, include: [ path.resolve(__dirname, 'src/components/**'), ], }, }, ], ], }, ], },This configuration includes the
jasonp-loaderin theusearray along with thebabel-loaderto handle the rest of the build process. Make sure you have installed thecomponentsdirectory in yoursrcdirectory.If you are still encountering the error, check the
includeoption in thejasonp-loaderconfiguration to ensure that it is properly configured and includes the necessary JavaScript files and modules in your build. Additionally, make sure you are importing thejasonp-loaderfrom the correct location in your webpack configuration, as specified in the documentation. - Install the
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部

