【发布时间】:2021-04-07 17:01:38
【问题描述】:
这是我的package.json
{
"name": "x",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "webpack --mode=development --watch",
"build": "webpack --mode=production"
},
"dependencies": {
"axios": "^0.21.0",
"vue-axios": "^3.2.0",
"vuex": "^3.6.2"
},
"devDependencies": {
"@types/node": "^14.14.37",
"css-loader": "^5.2.0",
"html-webpack-inline-source-plugin": "0.0.10",
"html-webpack-plugin": "^5.3.1",
"remove-files-webpack-plugin": "^1.1.3",
"sass": "^1.20.3",
"sass-loader": "^11.0.1",
"style-loader": "^2.0.0",
"ts-loader": "^8.1.0",
"typescript": "^4.2.3",
"url-loader": "^4.1.1",
"vue": "^2.6.10",
"vue-loader": "^15.7.0",
"vue-template-compiler": "^2.6.10",
"webpack": "^5.30.0",
"webpack-cli": "^4.6.0"
}
}
这是我的 webpack.config.js
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
const RemovePlugin = require('remove-files-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const path = require('path');
module.exports = (env, argv) => ({
// This is necessary because Figma's 'eval' works differently than normal eval
devtool: argv.mode === 'production' ? false : 'inline-source-map',
entry: {
ui: './src/ui.js', // The entry point for your UI code
code: './src/code.js' // The entry point for your plugin code
},
module: {
rules: [
// Converts TypeScript code to JavaScript
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
appendTsSuffixTo: [/\.vue$/]
}
},
// Enables including CSS by doing "import './file.css'" in your TypeScript code
{ test: /\.css$/, loader: [{ loader: 'style-loader' }, { loader: 'css-loader' }] },
{
test: /\.scss$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader'
},
{
loader: 'sass-loader',
options: {
implementation: require('sass')
}
}
]
},
{
test: /\.vue$/,
loader: 'vue-loader'
},
// Allows you to use "<%= require('./file.svg') %>" in your HTML code to get a data URI
{ test: /\.(png|jpg|gif|webp|svg)$/, loader: [{ loader: 'url-loader' }] }
]
},
// Webpack tries these extensions for you if you omit the extension like "import './file'"
resolve: { extensions: ['.tsx', '.ts', '.jsx', '.js'] },
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist') // Compile into a folder called "dist"
},
// Tells Webpack to generate "ui.html" and to inline "ui.ts" into it
plugins:
argv.mode === 'production'
? [
new VueLoaderPlugin(),
new RemovePlugin({
after: { include: ['dist/ui.js'] }
}),
new HtmlWebpackPlugin({
template: './src/ui.html',
filename: 'ui.html',
inlineSource: '.(js|css|scss)$',
chunks: ['ui']
}),
new HtmlWebpackInlineSourcePlugin()
]
: [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template: './src/ui.html',
filename: 'ui.html',
inlineSource: '.(js|css|scss)$',
chunks: ['ui']
}),
new HtmlWebpackInlineSourcePlugin()
]
});
错误
[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
- configuration.module.rules[4] should be one of these:
["..." | object { compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, sideEffects?, test?, type?, use? }, ...]
-> A rule.
Details:
* configuration.module.rules[4].loader should be a non-empty string.
-> A loader request.
更新依赖关系后一切都崩溃了,我收到了我不明白的错误消息,因为 loader 是一个字符串。我对 webpack 的了解非常有限。有人可以帮忙吗?
【问题讨论】:
-
那么您是否认真地在标题中提出“依赖更新后”的问题,而不是告诉您究竟更新了哪些依赖?
-
这就是我发布 package.json 的原因。我已经运行了 yarn upgrade --latest
-
如果错误是“依赖项更新后”,您需要发布版本 before 和 after - 而不仅仅是在...
标签: javascript vue.js webpack