小编Leg*_*est的帖子

在Webpack中加载静态JSON文件

我的代码在构造之后的某处:

var getMenu = function () {
    return window.fetch("portal/content/json/menu.json").then(function (data) {
        return data.json();
    });
};
Run Code Online (Sandbox Code Playgroud)

我尝试过webpack.config.js这个:

module: {
    loaders: [
        ...
        {
            test: /\.json$/,
            exclude: /node_modules/,
            use: [
                'file-loader?name=[name].[ext]&outputPath=portal/content/json'
            ]
        },
        ...
   ]
}
Run Code Online (Sandbox Code Playgroud)

项目结构:

dist
  content
     json
        menu.json <- this is missing

src
  content
     json
       menu.json <- source file
Run Code Online (Sandbox Code Playgroud)

题:

webpack如何复制src/content/json/menu.jsondist/content/json/menu.json

javascript json angularjs webpack

18
推荐指数
2
解决办法
3万
查看次数

标签 统计

angularjs ×1

javascript ×1

json ×1

webpack ×1