Webpack脚本加载器无法在Chrome中调试源代码

问题描述 投票:1回答:1

像很多人一样,我需要处理遗留代码,而不是想用webpack构建。有点奇怪。

我使用script-loader作为遗留代码。 (* .exec.js)它执行,但在chrome中,它不可能通过Ctrl+P到达源文件来放置断点。

TypeScript源是可用的,调试器在它们内部工作。 (像commons.ts)

这是正常的还是我错过了某处的配置/选项?

谢谢。

这是项目:https://github.com/Rouche/webpack-test初始项目有很多选项我试图最小化它。

为了方便:

package.json

{
  "name": "webpack-test",
  "version": "1.0.0",
  "description": "Webpack Tests",
  "main": "webpack.config.js",
  "dependencies": {},
  "devDependencies": {
    "autoprefixer": "^8.6.5",
    "clean-webpack-plugin": "^0.1.19",
    "compression-webpack-plugin": "^1.1.12",
    "css-loader": "^1.0.1",
    "cssnano": "^4.1.9",
    "mini-css-extract-plugin": "^0.4.5",
    "moment": "^2.24.0",
    "node-sass": "^4.11.0",
    "postcss-loader": "^2.1.5",
    "sass-loader": "^7.1.0",
    "script-loader": "^0.7.2",
    "source-map-loader": "^0.2.4",
    "style-loader": "^0.21.0",
    "ts-loader": "^4.5.0",
    "typescript": "^3.3.3",
    "webpack": "^4.29.3",
    "webpack-cli": "^3.2.3",
    "webpack-dev-server": "^3.1.14",
    "webpack-md5-hash": "0.0.6"
  },
  "scripts": {
    "prod": "webpack --env.cdn=http://localhost:8090/ --config webpack.config.js --mode production",
    "start": "webpack-dev-server --env.cdn=http://localhost:8090/ --env.WEBPACK_DEV_SERVER=true --mode development"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "author": "Jean-Francois Larouche",
  "license": ""
}

webpack.config.js

// webpack v4
const path = require('path');
const webpack = require('webpack'); //to access built-in plugins
const WebpackMd5Hash = require('webpack-md5-hash');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CompressionPlugin = require("compression-webpack-plugin")

const modeDev = 'development';

var configFn = (env, argv) => {


    const mode = argv ? argv.mode : modeDev;
    const development = mode ===  modeDev;

    console.log('Build mode: [' + mode + ']');

    var config = {
        mode: mode,
        devServer: {
            contentBase: [path.join(__dirname, 'resources'), path.join(__dirname, 'dist')],
            compress: false,
            port: 8090
        },
        devtool: development ? 'eval-source-map' : undefined,
        entry: {
            // To output only TypeScript as module see https://github.com/webpack/webpack/issues/4002
            lib: './src/scripts/lib.js',
            app: './src/scripts/app.js',
            typescript: './src/typescript/typescript.ts'
        },
        output: {
            path: path.resolve(__dirname, 'dist'),
            publicPath: env.cdn,
            filename: '[name].js',
            chunkFilename: '[name]-[chunkhash].js',
            library: ["TypeScript", "[name]"],
            libraryTarget: "umd",
//            devtoolModuleFilenameTemplate: '../[resource-path]',
        },
        module: {
            rules: [
                {
                    test: [/\.exec\.js$/],
                    exclude: /node_modules/,
                    use: ['script-loader']
                },
                {
                    test: /\.(sc|c)ss$/,
                    exclude: /node_modules/,
                    use: [ // loader: 'style-loader', // Adds CSS to the DOM by injecting a <style> tag
                        {
                            loader: MiniCssExtractPlugin.loader // Extract css
                        },
                        {
                            loader: 'css-loader', // Convert CSS to CommonJS
                            options: {importLoaders: 2}
                        },
                        {
                            loader: 'postcss-loader' // see postcss.config.js
                        },
                        {
                            loader: 'sass-loader'  // Compile to sass
                        }]
                },
                {
                    test: /\.ts$/,
                    exclude: /node_modules/,
                    use: ['ts-loader']
                }]
        },
        resolve: {
            extensions: ['.js', '.json', '.ts']
        },
        externals: {
            moment: 'moment',
            jquery: 'jQuery',
            $: '$'
        },
        plugins: [
            new webpack.LoaderOptionsPlugin({
                //test: /postcss-loader$/, // only for this module
                options: {
                    mode: mode
                }
            }),
            new WebpackMd5Hash(),
            new MiniCssExtractPlugin({
                filename: '[name]-[chunkhash].css',
            })
        ]
    };

    if (!development) {
        config.plugins.push(
            new CompressionPlugin({
                asset: '[path].gz[query]',
                algorithm: 'gzip',
                test: /\.js$|\.css$|\.html$/,
                threshold: 100,
                minRatio: 0.9
            })
        );
    }
    // Ignore all locale files of moment.js
    config.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/));

    // Don't destroy dist folder with webpack-dev-server
    if (!env || !env.WEBPACK_DEV_SERVER) {
        config.plugins.unshift(new CleanWebpackPlugin('dist', {}));
    }

    console.log('Config: [' + JSON.stringify(config) + ']');

    return config;
};

module.exports = (env, argv) => {
    return configFn(env, argv);
};
webpack google-chrome-devtools source-maps
1个回答
0
投票

好吧,我终于找到了一个小缺失选项:

https://github.com/webpack-contrib/script-loader/issues/30

使用Ctrl+P源文件名看起来像script:///C:/[full path to file].js

© www.soinside.com 2019 - 2024. All rights reserved.