Не генерируются sourcemaps
Собрал свою сборку для разработки фронта, gulp для стилей, картинок и тд, webpack для js. Работают они через webpack-stream. Также в проекте использую typescript. Проблема в том, что неправильно генерируются sourcemaps
Вот таск для сборки в gulp:
function js(mode){
/*
* Javascript files
* mode = production | development
*/
return function javascript(){
return gulp.src(`${SRC_PATH}/js/main.tsx`, {
allowEmpty: true
})
//Linters
.pipe(eslint())
.pipe(eslint.formatEach('compact', process.stderr))
.pipe(eslint.failAfterError())
//Send webpack
.pipe(webpackStream({
...webpackConfig,
mode,
watch: mode !== 'production',
devtool: 'source-map'
}), webpack)
//Create source maps
.pipe(sourceMap.init({loadMaps: true}))
.pipe(through.obj(function (file, enc, cb) {
/*
* Dont pipe through any source map files as
* it will be handled by gulp-sourcemaps
*/
const isSourceMap = /\.map$/.test(file.path);
if (!isSourceMap) {
this.push(file);
}
cb();
}))
.pipe(concat('bundle.js'))
.pipe(sourceMap.write('.'))
// .pipe(mode === 'production' ?
// uglify() :
// through.obj((chunk, enc, cb) =>
// cb(null, chunk))
// )
//Save
.pipe(gulp.dest(`${DIST_PATH}/js`))
//Reload
.pipe(browserSync.stream());
};
}
webpack.config.js
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const conf = {
output: {
filename: 'js/[name].js',
path: path.resolve(__dirname, './dist')
},
module: {
rules: [
// {
// test: /\.tsx?/,
// use: 'ts-loader',
// exclude: '/node_modules/'
// },
{
test: /\.(js|ts)x?$/,
use: 'cache-loader',
exclude: '/node_modules/'
},
{
test: /\.(ts|js)x?$/,
loader: 'babel-loader',
exclude: '/node_modules/',
query: {
presets: ['react', 'es2015']
}
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
React: 'react',
ReactDOM: 'react-dom'
})
],
resolve: {
alias: {
modules: path.resolve(__dirname, 'node_modules')
},
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
optimization: {
minimizer: [
new TerserPlugin({
cache: true
})
]
}
};
module.exports = conf;