Va1 / string-replace-loader

Replace loader for Webpack
MIT License
250 stars 57 forks source link

Sourcemaps seem to break when replacing "ngInject" prologues. #18

Closed derekdon closed 7 years ago

derekdon commented 7 years ago

I noticed if I use this loader to replace the "ngInject"; prologues my source maps no longer open the original file.

{
    loader: 'string-replace-loader',
    options: {
        multiple: [
            {
                search: /["']ngInject["'];*/,
                replace: '',
                flags: 'g'
            }
        ]
    }
},
{
    loader: 'ng-annotate-loader'
},
{
    loader: 'babel-loader',
    options: {
        cacheDirectory: true
    }
},

Perhaps I'm missing something? If I take out the string-replace-loader source maps are okay again.

Avol-V commented 7 years ago

I have the same problem. Currently this plugin breaks sourcemaps, but it should just leave them as it is.

Va1 commented 7 years ago

@derekdon @Avol-V which kind of sourcemaps do you use, folks? I guess, this issue is only about inline sourcemaps

Avol-V commented 7 years ago

No, I use external sourcemaps. There is a parts from my webpack.config.js:

    devtool: 'source-map',
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: 'string-replace-loader',
                        options: {
                            search: /\b_import\(/g,
                            replace: 'import(',
                        },
                    },
                    {
                        loader: 'ts-loader',
                        options: {
                            configFileName: './app/tsconfig.json',
                        }
                    },
                ]
            }
        ],
    },
snipking commented 7 years ago

Same to me.

devtool: "eval-source-map",

module: {
        rules: [
            // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
            {   test: /\.tsx?$/,
                // loaders: ["babel-loader", "ts-loader"],
                use: [
                    {
                        loader: 'string-replace-loader',
                        options: {
                            search: '_import\\(',
                            replace: 'import(',
                            flags: 'g'
                        }
                    },
                    {
                        loader: 'babel-loader'
                    },
                    {
                        loader: 'ts-loader'
                    },
                ],
                include: path.join(__dirname, 'src')
            }
      ]
}
donaldpipowitch commented 7 years ago

@snipking I basically have the same setup like you. I hope my PR will fix this: https://github.com/Va1/string-replace-loader/pull/28.