小编XEn*_*ise的帖子

webpack.config.js中的json-loader无法正常工作

我正在尝试按照反应教程,我的webpack.config.js文件如下:

var webpack = require("webpack");
var pth = require("path");

module.exports = {
entry: "./src/index.js",
output: {
    path: __dirname + "/dist",
    filename: "bundle.js"
},
devServer: {
    inline: true,
    contentBase: './dist',
    port: 3000
},
module: {
    rules: [
      { test: /\.js$/, exclude: /(node_modules)/, use: 'babel-loader' },
      { test: /\.json$/, exclude: /(node_modules)/, use: 'json-loader' }
    ]
  }
} 
Run Code Online (Sandbox Code Playgroud)

虽然我的代码文件如下:我在lib.js中创建了组件,并且在index.js中完成了渲染,最终在index.html的HTML div中调用

lib.js

import React from 'react'
import text from './titles.json'

export const hello = (
<h1 id='title'
    className='header'
    style={{backgroundColor: 'purple', color: 'yellow'}}>
    {text.hello}    
</h1> …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs webpack

5
推荐指数
1
解决办法
4801
查看次数

标签 统计

javascript ×1

reactjs ×1

webpack ×1