Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

react - webpack.config.js False report provider provider错误 #241

Open
old-zsh opened this issue Sep 12, 2018 · 3 comments
Open

react - webpack.config.js False report provider provider错误 #241

old-zsh opened this issue Sep 12, 2018 · 3 comments

Comments

@old-zsh
Copy link

old-zsh commented Sep 12, 2018

var webpack = require('webpack');
var path = require('path');

// variables
var isProduction = process.argv.indexOf('-p') >= 0 || process.env.NODE_ENV === 'production';
var sourcePath = path.join(__dirname, './src');
var outPath = path.join(__dirname, './dist/static');
var appPath = path.join(sourcePath, '/app');
var commonPath = path.join(sourcePath, '/common');
var servicePath = path.join(sourcePath, '/service');
var antdPath = path.join(sourcePath, '/library/ant-design/components');
var langPath = path.join(sourcePath, '/app/assets/localLang');
var errCodeFnPath = path.join(sourcePath, '/app/utils/errCodeFn.ts');

// plugins
var HtmlWebpackPlugin = require('html-webpack-plugin');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
var WebpackCleanupPlugin = require('webpack-cleanup-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

// 配置 HappyPack
var HappyPack = require('happypack'),
os = require('os'),
happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length })

module.exports = {
context: sourcePath,
entry: {
app: './main.tsx'
},
output: {
path: outPath,
filename: 'bundle.js',
chunkFilename: '[hash]/[chunkhash].js',
publicPath: isProduction ? '/static/' : ''
},
target: 'web',
resolve: {
extensions: ['.js', '.ts', '.tsx'],
mainFields: ['module', 'browser', 'main'],
alias: {
app: appPath,
common: commonPath,
service: servicePath,
antd: antdPath,
Lang: langPath,
errCodeFn: errCodeFnPath
}
},
resolveLoader: {
modules: ['node_modules', 'tools']
},
module: {
// loaders: [
// {
// test: /.js|jsx$/,
// loader: 'HappyPack/loader?id=jsHappy',
// exclude: /node_modules/
// }
// ],
rules: [
{
test: /.tsx?$/,
use: [
isProduction && {
loader: 'babel-loader',
options: { plugins: ['react-hot-loader/babel'] }
},
'ts-loader',
{
loader: 'ui-loader',
options: {
'lib': 'antd',
'camel2': '-',
'style': 'style/index.less'
}
},
'happypack/loader'
].filter(Boolean)
},
{
test: /.less$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options: {
sourceMap: true,
modules: true,
localIdentName: '[local]___[hash:base64:5]'
}
},
{
loader: 'less-loader'
}
],
include: [appPath]
},
{
test: /.css$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options: {
modules: false
}
},
{
loader: 'less-loader'
}
],
include: [appPath]
},
{
test: /.less$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader'
},
{
loader: 'less-loader',
options: {
javascriptEnabled: true
}
}
],
exclude: [appPath]
},
{ test: /.(png|svg)$/, use: 'url-loader?limit=10000' },
{ test: /.(jpg|gif)$/, use: 'file-loader' }
]
},
optimization: {
splitChunks: {
name: true,
cacheGroups: {
commons: {
chunks: 'initial',
minChunks: 2
},
vendors: {
test: /[\/]node_modules[\/]/,
chunks: 'all',
priority: -10
}
}
},
runtimeChunk: true
},
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: 'development',
DEBUG: false
}),
new WebpackCleanupPlugin(),
new MiniCssExtractPlugin({
filename: '[contenthash].css',
disable: !isProduction
}),
new HtmlWebpackPlugin({
title: 'DuoOffice',
filename: isProduction ? '../index.html' : 'index.html',
template: 'pug-loader!src/index.jade'
}),

// copy custom static assets
new CopyWebpackPlugin([
  {
    from: path.resolve(__dirname, 'static'),
    to: isProduction ? '' : 'static',
    ignore: ['.*']
  }
]),
new HappyPack({
  loaders: [{
    loader: 'babel-loader',
  }]
})
//如果有单独提取css文件

],
devServer: {
contentBase: sourcePath,
hot: true,
inline: true,
historyApiFallback: {
disableDotRule: true
},
disableHostCheck: true,

proxy: {
  '/account': {
    'target': 'http://localhost:8007',
    'changeOrigin': true
  }
},
stats: 'minimal'

},
node: {
fs: 'empty',
net: 'empty'
}
};

Uploading 1.png…
14 |
15 | ReactDOM.render(

16 | <Provider {...{ store }}>
| ^
17 | <ConnectedRouter {...{ history }}>
18 |
19 |

Child html-webpack-plugin for "../index.html":
1 asset
Entrypoint undefined = ../index.html
[0] ../node_modules/pug-loader!./index.jade 1.09 KiB {0} [built]
[2] external "fs" 42 bytes {0} [optional] [built]
+ 1 hidden module
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: webpack -p --progress --colors
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mac/.npm/_logs/2018-09-12T13_10_31_200Z-debug.log

@old-zsh
Copy link
Author

old-zsh commented Sep 12, 2018

[ ![1](https://user-images.githubusercontent.com/20679549/45427309-1dd94b00-b6d1-11e8-9b86-6031919bd5de.png) ](url)

@xccjk
Copy link

xccjk commented Jun 9, 2021

I also encountered the same problem, it seems to exist on webpack5

@xccjk
Copy link

xccjk commented Jun 9, 2021

I have mentioned an issue under webpack, but it seems that there is no j'j

issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants