自从将 webpack 升级到版本 3 并将我的其他包升级到各自的最新版本后,我收到一个错误。我将它用于具有 office ui fabric react 的应用程序,但是我找不到错误。据我了解,我的块的加载顺序是正确的,那么这里有什么问题?
这是我的 webpack 配置:
var webpack = require('webpack');
var path = require('path');
var config = {
entry: {
vendor: ["jquery", "react", "react-dom", "office-ui-fabric-react"]
},
//watch: true,
output: {
path: __dirname + "/dist",
filename: './[name].js'
},
devtool: 'source-map',
devServer: {
contentBase: path.resolve(__dirname, './dist')
},
resolve: {
alias: {
Content: path.resolve(__dirname, "Content")
},
extensions: ['.ts', '.tsx', '.js']
},
plugins: [
new webpack.optimize.CommonsChunkPlugin("vendor")
],
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{ loader: "ts-loader" }
]
},
{
test: /\.scss$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" },
{ loader: "sass-loader" }
]
},
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" }
]
}
]
}
}
config.entry.projectrecord = "./src/apps/csr_projects";
config.entry.contractcsr = "./src/apps/csr_contracts";
config.entry.finance = "./src/apps/finance";
config.entry.wpreviewer = "./src/apps/wpreviewer";
module.exports = config;
还有我的 package.json
{
"name": "MyApp",
"version": "1.0.0",
"description": "SharePoint Add-In",
"main": "index.js",
"types": "main.d.ts",
"repository": "repo_url",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Me",
"license": "UNLICENSED",
"devDependencies": {
"@types/jquery": "~3.2.16",
"@types/react": "16.0.25",
"@types/react-dom": "^16.0.3",
"@types/sharepoint": "^2016.0.2",
"@uifabric/icons": "^5.2.0",
"css-loader": "^0.28.7",
"jquery": "^3.2.1",
"load-themed-styles": "^1.2.0",
"node-sass": "^4.7.1",
"office-ui-fabric-react": "^5.23.0",
"raw-loader": "^0.5.1",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"sass-loader": "^6.0.6",
"style-loader": "^0.19.0",
"systemjs": "^0.20.19",
"ts-loader": "^3.1.1",
"typescript": "~2.6.1",
"webpack": "~3.8.1",
"webpack-dev-server": "^2.9.4"
},
"dependencies": {}
}
编辑:问题只存在于 IE 中。Chrome 和 FF 解析生成的脚本没有问题。
编辑 2:当我使用产品构建时,我的供应商捆绑包中出现错误“设置未定义”。看来 IE 不支持这个。我在我的 webpack 配置中包含了一组 polyfill,但错误仍然存在。