我正在使用webpack和Angular6。自昨天以来,css文件没有明显变化,我没有编译npm run build:aot:prod在创建main-xxx.css时出现问题,bugsnag通知我认为它正在尝试重写一个已经存在并且无法成功完成构建的文件。
有趣的是,如果服务器正确编译,则在服务器上部署,但是在我的计算机上,如果不正确,则会出现以下错误: 冲突(409)-dist / main-f751fc480956a7a013da.css的源映射文件重复。今天早上有一段时间他确实完成了构建,但大多数时候没有。我找到了一种配置替代的解决方案:BugsnagSourceMapUploaderPlugin中为true,但是我不喜欢它,因为在从未重现此错误之前。
似乎它试图编译css(用sass创建)两次。
如果有人遇到相同的问题或知道如何调试以查找故障,它将对我有很大帮助。 预先非常感谢。
这是我的webpack-prod配置
/**
* @author: @AngularClass
*/
const helpers = require('./helpers');
const buildUtils = require('./build-utils');
/**
* Used to merge webpack configs
*/
const webpackMerge = require('webpack-merge');
/**
* The settings that are common to prod and dev
*/
const commonConfig = require('./webpack.common.js');
/**
* Webpack Plugins
*/
const SourceMapDevToolPlugin = require('webpack/lib/SourceMapDevToolPlugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin');
const PurifyPlugin = require('@angular-devkit/build-optimizer').PurifyPlugin;
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const {BugsnagSourceMapUploaderPlugin} = require('webpack-bugsnag-plugins');
function getUglifyOptions(supportES2015) {
const uglifyCompressOptions = {
pure_getters: true, /* buildOptimizer */
// PURE comments work best with 3 passes.
// See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926.
passes: 3 /* buildOptimizer */
};
return {
ecma: supportES2015 ? 6 : 5,
warnings: false, // TODO verbose based on option?
ie8: false,
mangle: true,
compress: uglifyCompressOptions,
output: {
ascii_only: true,
comments: false
}
};
}
module.exports = function (env) {
const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
const supportES2015 = buildUtils.supportES2015(buildUtils.DEFAULT_METADATA.tsConfigPath);
const METADATA = Object.assign({}, buildUtils.DEFAULT_METADATA, {
host: process.env.HOST || 'localhost',
port: process.env.PORT || 8080,
ENV: ENV,
HMR: false
});
// set environment suffix so these environments are loaded.
//METADATA.envFileSuffix = METADATA.E2E ? 'e2e.prod' : 'prod';
METADATA.envFileSuffix = METADATA.envFileSuffix || 'pre';
return webpackMerge(commonConfig({env: ENV, metadata: METADATA}), {
/**
* Options affecting the output of the compilation.
*
* See: http://webpack.github.io/docs/configuration.html#output
*/
output: {
/**
* The output directory as absolute path (required).
*
* See: http://webpack.github.io/docs/configuration.html#output-path
*/
path: helpers.root('dist'),
/**
* Specifies the name of each output file on disk.
* IMPORTANT: You must not specify an absolute path here!
*
* See: http://webpack.github.io/docs/configuration.html#output-filename
*/
filename: '[name].[chunkhash].bundle.js',
/**
* The filename of the SourceMaps for the JavaScript files.
* They are inside the output.path directory.
*
* See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename
*/
sourceMapFilename: '[file].map',
/**
* The filename of non-entry chunks as relative path
* inside the output.path directory.
*
* See: http://webpack.github.io/docs/configuration.html#output-chunkfilename
*/
chunkFilename: '[name].[chunkhash].chunk.js'
},
module: {
rules: [
/**
* Extract CSS files from .src/styles directory to external CSS file
*/
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
include: [helpers.root('src', 'styles')]
},
/**
* Extract and compile SCSS files from .src/styles directory to external CSS file
*/
{
test: /\.scss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
include: [helpers.root('src', 'styles')]
}
]
},
/**
* Add additional plugins to the compiler.
*
* See: http://webpack.github.io/docs/configuration.html#plugins
*/
plugins: [
new SourceMapDevToolPlugin({
filename: '[file].map[query]',
moduleFilenameTemplate: '[resource-path]',
fallbackModuleFilenameTemplate: '[resource-path]?[hash]',
sourceRoot: 'webpack:///'
}),
new MiniCssExtractPlugin({ filename: '[name]-[hash].css', chunkFilename: '[name]-[chunkhash].css' }),
new PurifyPlugin(), /* buildOptimizer */
new HashedModuleIdsPlugin(),
/**
* Plugin: UglifyJsPlugin
* Description: Minimize all JavaScript output of chunks.
* Loaders are switched into minimizing mode.
*
* See: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
*
* NOTE: To debug prod builds uncomment //debug lines and comment //prod lines
*/
new UglifyJsPlugin({
sourceMap: false,
parallel: true,
uglifyOptions: getUglifyOptions(supportES2015)
}),
new BugsnagSourceMapUploaderPlugin({
apiKey: METADATA.bugsnagKey,
publicPath: 'dist'
})
],
/**
* Include polyfills or mocks for various node stuff
* Description: Node configuration
*
* See: https://webpack.github.io/docs/configuration.html#node
*/
node: {
global: true,
crypto: 'empty',
process: false,
module: false,
clearImmediate: false,
setImmediate: false
}
});
};
答案 0 :(得分:0)
是的,泽维尔是对的。我遇到过同样的问题。它在 webpack.prod.js 文件下。默认情况下不启用覆盖。我在项目中用appVersion搜索。
new BugsnagSourceMapUploaderPlugin({
apiKey: 'YOUR_API_KEY',
appVersion: '4.0.0.038',
overwrite: true
})
可以在 here 的 BugSnag GitHub 页面中找到详细信息。