我是他前端开发的新手。我正在使用最新的vscode编辑器使用pnpjs在sharepoint 2013中创建某些功能。我想到了使用捆绑逻辑,以下是我的package.json文件
"devDependencies": {
"@babel/core": "^7.5.4",
"@babel/plugin-proposal-class-properties": "^7.5.0",
"@babel/plugin-proposal-numeric-separator": "^7.2.0",
"@babel/plugin-proposal-object-rest-spread": "^7.5.4",
"@babel/preset-env": "^7.5.4",
"@babel/preset-typescript": "^7.3.3",
"@pnp/common": "^1.3.4",
"@pnp/logging": "^1.3.4",
"@pnp/odata": "^1.3.4",
"@pnp/polyfill-ie11": "^1.0.2",
"@pnp/sp": "^1.3.4",
"@pnp/sp-clientsvc": "^1.3.4",
"@pnp/sp-taxonomy": "^1.3.4",
"@types/jquery": "^3.3.30",
"@types/sharepoint": "^2016.1.3",
"babel-loader": "^8.0.4",
"bootstrap": "^4.3.1",
"es6-promise": "^4.2.8",
"expose-loader": "^0.7.5",
"gulp": "^4.0.2",
"gulp-autoprefixer": "^6.1.0",
"gulp-clean-css": "^4.2.0",
"gulp-concat": "^2.6.1",
"gulp-minify": "^3.1.0",
"gulp-rename": "^1.4.0",
"gulp-sass": "^4.0.2",
"gulp-sourcemaps": "^2.6.5",
"gulp-spsave": "^3.1.1",
"gulp-uglify": "^3.0.2",
"jquery": "^3.4.1",
"popper.js": "^1.15.0",
"typescript": "^3.5.3",
"webpack": "^4.35.3",
"webpack-cli": "^3.3.6",
"webpack-stream": "^5.2.1",
"whatwg-fetch": "^3.0.0"
},
"dependencies": {
"@babel/polyfill": "^7.4.4"
}
在我的代码中,我使用string.startswith和endswith。我还导入了@ babel / polyfill。 一旦将代码打包并加载到Sharepoint中,我将收到以下错误
Sys.ParameterCountException: Parameter count mismatch.
at Function.Error$create [as create] (http://dmsdev1.idmdevnet.local/ScriptResource.axd?d=zNWUcKQTJAqR694smeMWKzqs8P67Zy_OHvbHxIJb06_wxuxiO2Ej81ilGwN81XqkKHJ4kIiagFjsesYqZN9zkvQcYTKL6_mwcfWWkelGdAQYymwN3bB8xr4MuTbbgf4xKUkBjaoLGx8wv0Rn2Dd0jnAD81oEtzPiEkYiWtZ1i_6ym4QvbFWv2D42xJyhG1-C0&t=ffffffff999c3159:237:15)
at Function.Error$parameterCount [as parameterCount] (http://dmsdev1.idmdevnet.local/ScriptResource.axd?d=zNWUcKQTJAqR694smeMWKzqs8P67Zy_OHvbHxIJb06_wxuxiO2Ej81ilGwN81XqkKHJ4kIiagFjsesYqZN9zkvQcYTKL6_mwcfWWkelGdAQYymwN3bB8xr4MuTbbgf4xKUkBjaoLGx8wv0Rn2Dd0jnAD81oEtzPiEkYiWtZ1i_6ym4QvbFWv2D42xJyhG1-C0&t=ffffffff999c3159:413:21)
at Function$_validateParameterCount [as _validateParameterCount] (http://dmsdev1.idmdevnet.local/ScriptResource.axd?d=zNWUcKQTJAqR694smeMWKzqs8P67Zy_OHvbHxIJb06_wxuxiO2Ej81ilGwN81XqkKHJ4kIiagFjsesYqZN9zkvQcYTKL6_mwcfWWkelGdAQYymwN3bB8xr4MuTbbgf4xKUkBjaoLGx8wv0Rn2Dd0jnAD81oEtzPiEkYiWtZ1i_6ym4QvbFWv2D42xJyhG1-C0&t=ffffffff999c3159:118:23)
at Function$_validateParams [as _validateParams] (http://dmsdev1.idmdevnet.local/ScriptResource.axd?d=zNWUcKQTJAqR694smeMWKzqs8P67Zy_OHvbHxIJb06_wxuxiO2Ej81ilGwN81XqkKHJ4kIiagFjsesYqZN9zkvQcYTKL6_mwcfWWkelGdAQYymwN3bB8xr4MuTbbgf4xKUkBjaoLGx8wv0Rn2Dd0jnAD81oEtzPiEkYiWtZ1i_6ym4QvbFWv2D42xJyhG1-C0&t=ffffffff999c3159:70:18)
at String$startsWith (http://dmsdev1.idmdevnet.local/ScriptResource.axd?d=zNWUcKQTJAqR694smeMWKzqs8P67Zy_OHvbHxIJb06_wxuxiO2Ej81ilGwN81XqkKHJ4kIiagFjsesYqZN9zkvQcYTKL6_mwcfWWkelGdAQYymwN3bB8xr4MuTbbgf4xKUkBjaoLGx8wv0Rn2Dd0jnAD81oEtzPiEkYiWtZ1i_6ym4QvbFWv2D42xJyhG1-C0&t=ffffffff999c3159:491:22)
at String.startsWith (http://dmsdev1.idmdevnet.local/sites/dms1/Style%20Library/DMS/customjs/app-bundle.js:9680:21)
at new Sys$UI$DomEvent (http://dmsdev1.idmdevnet.local/ScriptResource.axd?d=zNWUcKQTJAqR694smeMWKzqs8P67Zy_OHvbHxIJb06_wxuxiO2Ej81ilGwN81XqkKHJ4kIiagFjsesYqZN9zkvQcYTKL6_mwcfWWkelGdAQYymwN3bB8xr4MuTbbgf4xKUkBjaoLGx8wv0Rn2Dd0jnAD81oEtzPiEkYiWtZ1i_6ym4QvbFWv2D42xJyhG1-C0&t=ffffffff999c3159:3986:16)
此错误即将到来是因为sharepoint具有microsoft.ajax文件,该文件中定义了带一个参数的字符串原型,并且由于绑定而导致我的代码已更改。 在执行过程中,而不是引用polyfill函数,浏览器将执行microsoft函数,并且出现上述错误
我不知道如何排除单个polyfill,因此我尝试分割文件,并试图避免加载此模块,但是它不起作用。 我尝试在babelrc中使用参数'useBuiltIns',但没有成功。我使用了“输入/使用”模式 我的webpack配置如下
var path = require('path');
module.exports = {
devtool: 'inline-source-map',
// Change to your "entry-point".
entry: {
app: './app/scripts/app.ts',
host: './app/hostfiles/dmsentry.ts'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name]-bundle.js',
library: ['d1', '[name]'],
libraryTarget: 'var'
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json']
},
module: {
rules: [{
// Include ts, tsx, js, and jsx files.
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
loader: 'babel-loader',
}
],
},
mode: 'development',
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
test(mod, chunk) {
//
// Only node_modules are needed
console.log(mod.resource);
//console.log(mod.userRequest);
if (!mod.context.includes('node_modules')) {
return false;
}
if (["es6.string.ends-with.js","es6.string.starts-with.js"].some(str => mod.userRequest.indexOf(str) > -1)) {
// console.log(chunk.name);
return false;
}
// console.log(mod.resource);
return true;
},
filename: '[name].bundle.js',
chunks: 'all',
reuseExistingChunk: true,
automaticNameDelimiter: '-'
}
}
}
}
};
我的babelrc如下
{
"presets": [
["@babel/env",{
"targets": {
"browsers": ["last 2 versions", "safari >= 7"]
}
}],
["@babel/typescript",{"allowNamespaces":true}]
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"
]
}
我的吞噬任务如下
const gulp = require('gulp');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const webpackConfig = require('./webpack.config.js');
gulp.task('appjs', () => {
return gulp.src('app/scripts/app.ts')
.pipe(webpackStream(webpackConfig), webpack)
.pipe(gulp.dest('dist/customjs'));
});
任何想法如何排除模块或修复错误。我无法更改/阻止Sharepoint中的micorsoft ajax文件。
希望我很清楚,任何帮助将不胜感激!谢谢