amireh / happypack

Happiness in the form of faster webpack build times.
MIT License
4.23k stars 125 forks source link

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

Open old-zsh opened 6 years ago

old-zsh commented 6 years ago

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]

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 commented 6 years ago

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

xccjk commented 3 years ago

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

xccjk commented 3 years ago

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

issue