0

我正在尝试将 Vue.js 与 ASP.Net 核心 mvc 项目集成。我正在学习某个教程,但是当我尝试构建 npm 项目时卡住了。

我收到以下错误:'npm:无效的配置对象。Webpack 已使用与 API 模式不匹配的配置对象进行初始化。

这是我的 webpack.config.js 文件

var path = require("path");
var webpack = require("webpack");
var fs = require("fs");

var appBasePath = './Scripts/'; // where the source files are located
var publicPath = '../bundle'; // public path to modify asset urls. eg: 
'../bundle' =? 'www.example.com/bundle/main.js'
var bundleExportPath = './wwwroot/bundle/'; //directory to export built files

var jsEntries = {}; // listing to compile

// We search for js files inside basePath folder and make those as entries
fs.readdirSync(appBasePath).forEach(function (name) {

    // assumption: modules arre located in seperate directory and each module component is imported to index.js of particular module
var indexFile = appBasePath + name + '/index.js'
if (fs.existsSync(indexFile)) {
    jsEntries[name] = indexFile
}
});

const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

module.exports = {
    entry: jsEntries,
    output: {
        path: path.resolve(__dirname, bundleExportPath),
        publicPath: publicPath,
        filename: '[name].js'
    },
    resolve: {
        extensions: ['.js', '.vue', '.json'],
        alias: {
            'vue$': 'vue/dist/vue.esm.js',
            '@': path.join(__dirname, appBasePath)
        }
    },
    modules: {
        loaders: [
            {
                test: /\.vue$/,
                loader: 'vue-loader',
                options: {
                    loaders: {
                         scss: 'vue-style-loader!css-loader!sass-loader', // <style lang="scss">
                         sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax' // <style lang="sass">
                    }
                }
            },
            {
                test: /\.scss$/,
                loader: 'style-loader!css-loader!sass-loader'
            },
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader'
            },
            {
                test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
                loader: 'file-loader'
            },
            {
                test: /\.(png|jpe?g|gif|svg)(\?\S*)?$/,
                loader: 'file-loader',
                query: {
                    name: '[name].[ext]?[hash]'
                }
            }
         ]
    },
    devtool: '#source-map', // #eval-source-map
}
module.exports.watch = process.env.WATCH === "true";
if (process.env.NODE_ENV === 'production') {
    module.exports.devtool = '#source-map'
    //https://vue-loader.vuejs.prg/en/workflow/production.html
    module.exports.plugins = (module.exports.plugins || []).concat([
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: '"production"'
            }
        }),
        new UglifyJsPlugin({
            "uglifyOptions":
            {
                compress: {
                    warnings: false
                },
                sourceMaps: true
            }
        }),
    ]);
}
else if (process.env.NODE_ENV === "dev") {
    module.exports.watch = true;
    module.exports.plugins = (module.exports.plugins || []).concat([
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: '"development"'
            }
        }),
    ]);
}

请问有什么帮助吗?

4

1 回答 1

0

哦,刚刚意识到什么都没有错,这只是一个错字(模块而不是模块)

于 2019-09-04T13:36:58.033 回答