Webpack构建过程 - 找不到模块:错误:无法解析模块*

时间:2017-01-07 01:37:13

标签: build webpack

我在尝试使用Webpack构建应用程序时收到很多错误,并且不知道该怎么做。我查看了其他解决方案,建议将诸如target: 'web'node: {fs: "empty"}之类的内容添加到webpack.config.prod.js,但这些都没有清除错误。运行sudo npm run build后,控制台中出现以下错误选择(总共约150个):

  错误在./~/ejs/lib/ejs.js找不到模块:错误:无法解析   / tidee / auth_app / node_modules / ejs / lib @中的模块'fs'   ./~/ejs/lib/ejs.js 47:9-22

     错误在./~/express/lib/request.js找不到模块:错误:无法   解决/ tidee / auth_app / node_modules / express / lib @中的模块'net'   ./~/express/lib/request.js 18:11-25

     错误在./~/node-pre-gyp/lib/node-pre-gyp.js找不到模块:错误:   无法解析'文件'或'目录'../package in   / tidee / auth_app / node_modules / node-pre-gyp / lib @   ./~/node-pre-gyp/lib/node-pre-gyp.js 60:16-37

     错误在./~/ps-tree/index.js找不到模块:错误:无法解析   / tidee / auth_app / node_modules / ps-tree @中的模块'child_process'   ./~/ps-tree/index.js 3:12-36

下面是我的webpack.config.prod.js文件:

const path = require('path');
var webpack = require("webpack");
var CompressionPlugin = require('compression-webpack-plugin');
const pkg = require("./package.json");

module.exports = {
    entry: {
        vendor: Object.keys(pkg.dependencies).filter(function (v) {
            return v;
        }),
        app: path.join(__dirname, '/client/src/app.jsx')
    },
    output: {
        path: path.join(__dirname, '/client/dist'),
        filename: '[name].js',
        publicPath: 'http://example.com/public/'
    },
    resolve: {
        root: path.resolve('./client/dist'),
        extensions: ['', '.js', '.jsx', '.less', '.css'],
        alias: {
            'jquery-ui': 'jquery-ui-dist/jquery-ui.js'
        }
    },
    module: {
        loaders: [{
            test: /\.js?$/,
            loaders: ['babel'],
            include: path.join(__dirname, '/shared')
        },{
            test: /\.jsx?$/,
            loaders: ['react-hot','babel?' + JSON.stringify({
                presets: ["es2015", "stage-0", "react"]
            })],
            include: path.join(__dirname, '/client/src')
        },{
            test: /\.less$/,
            loaders: ['style', 'css', 'less']
        },{
            test: /\.css$/,
            loaders: ['style', 'css']
        },
        {
            test: /\.ico$/,
            loader: "file-loader"
        },
        {
            test: /\.png$/,
            loader: "url-loader?limit=100000"
        },
        {
            test: /\.jpg$/,
            loader: "file-loader"
        },
        {
            test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'url?limit=10000&mimetype=application/font-woff'
        },
        {
            test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'url'
        },
        {
            test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'file'
        },
        {
            test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'url?limit=10000&mimetype=image/svg+xml'
        },{
            test: /\.json$/,
            loader: "json-loader"
        }]
    },

    plugins: [
        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': JSON.stringify('production')
            }
        }),
        new webpack.ProvidePlugin({
            "$":"jquery",
            "jQuery":"jquery",
            'global.jQuery': 'jquery'
        }),
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.NoErrorsPlugin(),
        new webpack.DefinePlugin({ 'typeof window': '\"object\"' }),
        new webpack.optimize.DedupePlugin(), //dedupe similar code
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        }),
        new CompressionPlugin({
            asset: "[path].gz[query]",
            algorithm: "gzip",
            test: /\.js$|\.css$|\.html$/,
            threshold: 10240,
            minRatio: 0.8
        })
    ]
};

注意:我使用的是Node v7.2.1和Webpack v1.14.0

0 个答案:

没有答案