当前位置: 首页 > 知识库问答 >
问题:

使用Babel和webpack与Aurela生成. js源映射

巢睿
2023-03-14

我试图让js源地图在使用webpack、babel-loader和Aurela时被发出(不确定Aurela在这种情况下是否重要,但我正在包括它以防它重要)。我甚至还没有开始学习如何使用webpack一周。我遇到很多困难的一件事是让js源地图被发出。

我试图使用的答案:

使用babel和webpack时如何生成源地图?

网页包开发服务器不生成源地图

但不幸的是,我仍然只是在chrome的开发者工具窗口中看到1.bundle.js和bundle.js作为脚本文件。

这里我将包括我的package.json:

{
  "name": "companyname.projectname.web",
  "version": "0.1.0",
  "sasslintConfig": "./.sass-lint.yml",
  "description": "lol",
  "main": "index.js",
  "scripts": {
    "dev": "webpack-dev-server -d --config webpack.config.js --hot --inline --progress --devtool eval",
    "build": "webpack --config webpack.config.js --progress --profile",
    "prod": "webpack -p --config webpack.prod.config.js --progress --devtool source-map",
    "test": "karma start",
    "webdriver:update": "./node_modules/.bin/webdriver-manager update",
    "webdriver:start": "./node_modules/.bin/webdriver-manager start",
    "pree2e": "npm run webdriver:update -- --standalone",
    "e2e": "./node_modules/.bin/protractor"
  },
  "dependencies": {
    "aurelia-bootstrapper-webpack": "^1.0.0-beta.1.0.0",
    "aurelia-event-aggregator": "^1.0.0-beta.1.1.1",
    "aurelia-fetch-client": "^1.0.0-beta.1.1.0",
    "aurelia-framework": "^1.0.0-beta.1.1.3",
    "aurelia-history-browser": "^1.0.0-beta.1.1.2",
    "aurelia-logging-console": "^1.0.0-beta.1.1.4",
    "aurelia-pal-browser": "^1.0.0-beta.1.1.4",
    "aurelia-polyfills": "^1.0.0-beta.1.0.0",
    "aurelia-router": "^1.0.0-beta.1.1.1",
    "aurelia-templating-binding": "^1.0.0-beta.1.1.1",
    "aurelia-templating-resources": "^1.0.0-beta.1.1.1",
    "aurelia-templating-router": "^1.0.0-beta.1.1.1",
    "bluebird": "^3.3.4",
    "bootstrap": "^4.0.0-alpha.2",
    "exports-loader": "^0.6.3",
    "extract-text-webpack-plugin": "^1.0.1",
    "font-awesome": "^4.5.0",
    "imports-loader": "^0.6.5",
    "isomorphic-fetch": "^2.2.1",
    "jquery": "^2.2.3",
    "json-loader": "^0.5.4",
    "node-sass": "^3.6.0",
    "sass-loader": "^3.2.0",
    "tether": "^1.3.2",
    "whatwg-fetch": "^1.0.0"
  },
  "devDependencies": {
    "aurelia-tools": "^0.1.18",
    "aurelia-webpack-plugin": "^1.0.0-beta.1.0.0",
    "babel-core": "^6.7.2",
    "babel-eslint": "^5.0.0",
    "babel-loader": "^6.2.4",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-es2015-loose": "^7.0.0",
    "babel-preset-stage-1": "^6.5.0",
    "css-loader": "^0.23.1",
    "eonasdan-bootstrap-datetimepicker": "^4.15.35",
    "eslint": "^1.10.3",
    "file-loader": "^0.8.5",
    "html-loader": "^0.4.3",
    "html-webpack-plugin": "^2.9.0",
    "jasmine-core": "^2.4.1",
    "karma": "^0.13.21",
    "karma-babel-preprocessor": "^6.0.1",
    "karma-chrome-launcher": "^0.2.2",
    "karma-jasmine": "^0.3.7",
    "karma-webpack": "^1.7.0",
    "node-sass": "^3.4.2",
    "protractor": "^3.2.1",
    "raw-loader": "^0.5.1",
    "sass-loader": "^3.2.0",
    "style-loader": "^0.13.0",
    "url-loader": "^0.5.7",
    "wallaby-webpack": "0.0.21",
    "webpack": "^1.13.0",
    "webpack-dev-server": "^1.14.1"
  }
}

我的webpack.config.js:

/*eslint-disable no-var*/

var path = require('path');
var AureliaWebpackPlugin = require('aurelia-webpack-plugin');
var ProvidePlugin = require('webpack/lib/ProvidePlugin');

module.exports = {
  debug: true,
  devServer: {
    host: 'localhost',
    port: 3000
  },
  devtool: 'source-map',
  entry: {
    main: [
      './src/main'
    ]
  },
  output: {
    path: path.join(__dirname, 'build'),
    filename: 'bundle.js'
  },
  plugins: [
    new AureliaWebpackPlugin({
      src: path.resolve('./src')
    }),
    new ProvidePlugin({
      Promise: 'bluebird',
      jQuery: 'jquery',
      'window.Tether': 'tether',
      fetch: 'imports?this=>global!exports?global.fetch!whatwg-fetch'
    }),
    new ExtractTextPlugin('global.css', {
      allChunks: false
    })
  ],
  module: {
    loaders: [
      { test: /\.js$/, loader: 'babel', exclude: /node_modules/, query: { presets: ['es2015-loose', 'stage-1'], plugins: ['transform-decorators-legacy'] } },
      { test: /\.json$/, loader: 'json' },
      { test: /\.css$/, loader: 'style!css' },
      { test: /\.scss$/, loaders: ['style', 'css?sourceMap', 'sass?sourceMap'], include: path.resolve('./sass') },
      { test: /\.html$/, loader: 'html' },
      { test: /\.(png|gif|jpg)$/, loader: 'url?limit=8192' },
      { test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" },
      { test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" },
      { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" },
      { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" },
      { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" }
    ]
  },
  node: {
    fs: 'empty'
  }
};

别评判我,我还在学习这一切。如您所见,我已经在“dev”脚本中为webpack dev server命令启用了-d选项。我补充道:debug:truedevtool:“源代码映射”,但唉,我似乎找不到这些源代码映射在chrome开发者工具中的发布位置;这让我得出结论,它们根本没有被释放出来。

我确实在网页上发现了一些有趣的东西://。领域我所有的Aurelia js都在那里,除了它看起来像是由babel或webpack转换的。

共有1个答案

闻人鸿文
2023-03-14

替换此行:

...
"scripts": {
    "dev": "webpack-dev-server -d --config webpack.config.js --hot --inline --progress --devtool eval"
...

为此:

...
"scripts": {
    "dev": "webpack-dev-server -d --config webpack.config.js --hot --inline --progress --devtool source-map"
...

放入调试器 (用作断点)并保持浏览器的devtools打开。例如:

export class MyViewModel {
   constructor() {
     debugger;
     //...
   }
}

现在,您应该看到调试器在ES2016级别工作。

 类似资料:
  • 我是webpack的新手,我需要参与设置以生成源地图。我正在从命令行运行,该命令已成功编译。但我真的需要源地图。这是我的。 我对webpack很陌生,虽然这些文档并没有真正起到帮助,但我不确定这个问题具体是什么。

  • 问题内容: 我有: 我要捆绑的JS文件。 我想编译为CSS的LESS文件(将@imports解析为一个包)。 我希望将它们指定为两个单独的输入,并具有两个单独的输出(可能通过extract-text-webpack- plugin)。Webpack具有所有合适的插件/加载器来进行编译,但似乎不喜欢这种分离。 我已经看到了一些人的示例,这些人直接从JS需要他们的LESS文件,例如,其原因仅是告诉We

  • 我有一个webpack配置,当我直接调用webpack时,它会生成react包。由于我想合并热重新加载,所以我需要在端口3000上运行的development express服务器(服务APIendpoint)旁边运行webpack dev服务器 webpack.dev.config.js dev-server.js package.json脚本 如果我跑了 结果是一个新的js包和html:dis

  • koa-babel-webpack-boilerplate A simple boilerplate to create REST apps with koa@next (currently 2.0.0-alpha.3) babel (for async, await and stage-2 support) webpack How to use Boilerplate is packed wit

  • webpack-babel-env-deps Find dependencies to transpile with Babel. �� Read the docs! A webpack helper to find dependencies of your project that require transpilation with Babel (and @babel/preset-env)b

  • babel-plugin-webpack-alias This Babel 6 plugin allows you to use webpack aliases and most of webpack resolve features in Babel. This plugin is simply going to take the aliases defined in your webpack