Tôi có ứng dụng phản ứng helloworld đơn giản này được tạo từ một khóa học trực tuyến, tuy nhiên tôi gặp lỗi này:
Đối tượng cấu hình không hợp lệ. Webpack đã được khởi tạo bằng đối tượng cấu hình không khớp với lược đồ API. - cấu hình có thuộc tính không xác định 'postcss'. Các thuộc tính này hợp lệ: object {amd ?, bail ?, cache ?, context ?, dependencies ?, devServer ?, devtool ?, entry, externals ?, loader ?, module ?, name ?, node ?, output ?, performance? , plugins ?, hồ sơ ?, recordInputPath ?, recordO utputPath ?, recordsPath ?, giải quyết ?, giải quyếtLoader ?, thống kê ?, target ?, watch ?, watchOptions? } Đối với lỗi chính tả: vui lòng sửa chúng.
Đối với các tùy chọn trình tải: webpack 2 không còn cho phép các thuộc tính tùy chỉnh trong cấu hình. Bộ tải phải được cập nhật để cho phép các tùy chọn chuyển qua tùy chọn bộ tải trong module.rules. Cho đến khi các trình tải được cập nhật, người ta có thể sử dụng LoaderOptionsPlugin để chuyển các tùy chọn này cho trình tải: plugins: [new webpack.LoaderOptionsPlugin ({// test: /.xxx$/, // chỉ có thể áp dụng điều này cho một số tùy chọn mô-đun: {postcss: ...}})] - configuration.resolve có thuộc tính "root" không xác định. Các thuộc tính này là hợp lệ: object {alias ?, aliasFields ?, cachePredicate ?, descriptionFiles ?, thi hànhExtension ?, cưỡng chếModuleExtension ?, phần mở rộng ?, fileSystem ?, mainFields ?, mainFiles ?, moduleExtensions ?, mô-đun ?, plugin ?, giải quyết ?, liên kết tượng trưng ?, Bộ nhớ đệm không an toàn ?, useSyncFileSystemCalls? } - configuration.resolve.extensions [0] không được để trống.
Tệp webpack của tôi là:
// work with all paths in a cross-platform manner
const path = require('path');
// plugins covered below
const { ProvidePlugin } = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// configure source and distribution folder paths
const srcFolder = 'src';
const distFolder = 'dist';
// merge the common configuration with the environment specific configuration
module.exports = {
// entry point for application
entry: {
'app': path.join(__dirname, srcFolder, 'ts', 'app.tsx')
},
// allows us to require modules using
// import { someExport } from './my-module';
// instead of
// import { someExport } from './my-module.ts';
// with the extensions in the list, the extension can be omitted from the
// import from path
resolve: {
// order matters, resolves left to right
extensions: ['', '.js', '.ts', '.tsx', '.json'],
// root is an absolute path to the folder containing our application
// modules
root: path.join(__dirname, srcFolder, 'ts')
},
module: {
loaders: [
// process all TypeScript files (ts and tsx) through the TypeScript
// preprocessor
{ test: /\.tsx?$/,loader: 'ts-loader' },
// processes JSON files, useful for config files and mock data
{ test: /\.json$/, loader: 'json' },
// transpiles global SCSS stylesheets
// loader order is executed right to left
{
test: /\.scss$/,
exclude: [path.join(__dirname, srcFolder, 'ts')],
loaders: ['style', 'css', 'postcss', 'sass']
},
// process Bootstrap SCSS files
{
test: /\.scss$/,
exclude: [path.join(__dirname, srcFolder, 'scss')],
loaders: ['raw', 'sass']
}
]
},
// configuration for the postcss loader which modifies CSS after
// processing
// autoprefixer plugin for postcss adds vendor specific prefixing for
// non-standard or experimental css properties
postcss: [ require('autoprefixer') ],
plugins: [
// provides Promise and fetch API for browsers which do not support
// them
new ProvidePlugin({
'Promise': 'es6-promise',
'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch'
}),
// copies image files directly when they are changed
new CopyWebpackPlugin([{
from: path.join(srcFolder, 'images'),
to: path.join('..', 'images')
}]),
// copies the index.html file, and injects a reference to the output JS
// file, app.js
new HtmlWebpackPlugin({
template: path.join(__dirname, srcFolder, 'index.html'),
filename: path.join('..', 'index.html'),
inject: 'body',
})
],
// output file settings
// path points to web server content folder where the web server will serve
// the files from file name is the name of the files, where [name] is the
// name of each entry point
output: {
path: path.join(__dirname, distFolder, 'js'),
filename: '[name].js',
publicPath: '/js'
},
// use full source maps
// this specific setting value is required to set breakpoints in they
// TypeScript source in the web browser for development other source map
devtool: 'source-map',
// use the webpack dev server to serve up the web application
devServer: {
// files are served from this folder
contentBase: 'dist',
// support HTML5 History API for react router
historyApiFallback: true,
// listen to port 5000, change this to another port if another server
// is already listening on this port
port: 5000,
// proxy requests to the JSON server REST service
proxy: {
'/widgets': {
// server to proxy
target: 'http://0.0.0.0:3010'
}
}
}
};