File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -496,34 +496,20 @@ localhost:8080
496496Babel其实可以完全在 ` webpack.config.js ` 中进行配置,但是考虑到babel具有非常多的配置选项,在单一的` webpack.config.js ` 文件中进行配置往往使得这个文件显得太复杂,因此一些开发者支持把babel的配置选项放在一个单独的名为 ".babelrc" 的配置文件中。我们现在的babel的配置并不算复杂,不过之后我们会再加一些东西,因此现在我们就提取出相关部分,分两个配置文件进行配置(webpack会自动调用` .babelrc ` 里的babel配置选项),如下:
497497
498498```
499- // webpack.config.js
500499module.exports = {
501- devtool: 'eval-source-map',
502-
503- entry: __dirname + "/app/main.js",
504- output: {
505- path: __dirname + "/public",
506- filename: "bundle.js"
507- },
508-
509- module: {
510- loaders: [
511- {
512- test: /\.json$/,
513- loader: "json"
514- },
515- {
516- test: /\.js$/,
517- exclude: /node_modules/,
518- loader: 'babel'
519- }
520- ]
521- },
522-
523- devServer: {...} // Omitted for brevity
524- }
525-
526-
500+ ...
501+ module: {
502+ rules: [
503+ {
504+ test: /(\.jsx|\.js)$/,
505+ use: {
506+ loader: "babel-loader"
507+ },
508+ exclude: /node_modules/
509+ }
510+ ]
511+ }
512+ };
527513```
528514
529515```
@@ -579,7 +565,6 @@ module.exports = {
579565 ]
580566 }
581567};
582-
583568```
584569
585570> 请注意这里对同一个文件引入多个loader的方法。
You can’t perform that action at this time.
0 commit comments