我有配置webpack,如:
const extractSass = new ExtractTextPlugin({
filename: '[name]',
disable: process.env.NODE_ENV === "development"
});
module.exports = (env, options) => {
console.log(`env: ${env} mode: ${options.mode}`);
return {
entry: {
'css/index.css': [
entryDir + '/scss/index.scss',
],
},
output: {
path: buildDir,
// publicPath: 'css/',
filename: '[name]',
},
watch: (options.mode == 'development') ? true : false,
devtool: (options.mode == 'development') ? "source-map" : false,
module: {
rules: [
{
test: /\.scss$/,
loader: extractSass.extract({
use: [
{
loader: 'css-loader', options: {
sourceMap: true,
url: false
}
},
'postcss-loader',
{
loader: 'sass-loader', options: {
sourceMap: true,
url: false
}
}],
fallback: 'style-loader'
}),
},
],
},
plugins: [
new CleanWebpackPlugin(['assets/dist/css']),
extractSass
]
}
};
的package.json
{
"name": "webpackConf",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack --mode production",
"watch": "webpack --mode development"
},
"author": "",
"license": "ISC",
"devDependencies": {
"clean-webpack-plugin": "^0.1.19",
"css-loader": "^0.28.11",
"extract-text-webpack-plugin": "v4.0.0-alpha.0",
"file-loader": "^1.1.11",
"node-sass": "^4.8.3",
"postcss-loader": "^2.1.3",
"sass-loader": "^6.0.7",
"style-loader": "^0.20.3",
"webpack": "^4.12.0",
"webpack-cli": "^2.0.13",
"uglifyjs-webpack-plugin": "^1.2.5"
},
"dependencies": {
}
}
我的配置有效但我的源映射总是提示到index.scss文件,而不是实际文件。索引仅适用于我的部分@import文件。 我尝试了来自doc https://webpack.js.org/configuration/devtool/#devtool的选项,但它们似乎都没有效果。我应该使用或更新包以使其有效吗?
答案 0 :(得分:0)
我也面临类似的问题,然后与其他选项一起玩,下面的事情对我来说很好
devtool:(options.mode =='开发') “ eval”:false