我有一個最小的webpack1配置,我已經削減了一個龐大的項目,只是爲了重現這一點。如何獲取源圖文件以輸出到我的構建文件夾?
當我跑我的配置用的WebPack-dev的服務器,它工作得很好,除了該文件僅在localhost:port/bundle.js.map
不是在我的地方項目dist
文件夾進行訪問。
鏈接並指示回購:https://github.com/rublev/webpack-nosourcemaps
webpack.config.base.js
module.exports = {
output: {
path: path.join(process.cwd(), '/dist'),
publicPath: '/',
filename: 'bundle.js'
},
resolve: {
root: path.join(__dirname, ''),
modulesDirectories: [
'node_modules',
'app'
],
extensions: ['', '.html', '.js'] // removing '' makes everything explode
},
plugins: [
new HtmlWebpackPlugin({
title: 'webpack-sourcemap',
template: 'app/index.html'
})
],
module: {
loaders: [],
}
}
webpack.config.production.js
var config = require('./webpack.config.base.js')
config.devtool = 'source-map'
if (process.env.NODE_ENV !== 'test') {
config.entry = {
main: path.join(process.cwd(), '/app/') + 'app.js',
vendor: [
'react',
'react-dom'
]
}
}
config.output = {
path: path.join(process.cwd(), '/dist'),
pathInfo: true,
publicPath: '/',
filename: 'bundle.js'
}
config.module.loaders = config.module.loaders.concat([
{
test: /\.js$/,
loaders: ['babel'],
exclude: /node_modules/
}
])
config.plugins = config.plugins.concat([
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.OccurenceOrderPlugin(true),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.js'
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
])
module.exports = config