【问题标题】:React - Django webpack config with dynamic 'output'React - 具有动态“输出”的 Django webpack 配置
【发布时间】:2015-12-23 03:02:14
【问题描述】:

有:

我有一个 Django 应用程序。它对前端有反应。我有 2 个 django 应用程序。 movies_listseries_list。我在baseapplication/movies_list/interfaces/baseapplication/series_list/interfaces/ 中有我所有的.jsx 文件。 2 个应用程序的入口点在 web-pack.config.jsentry 对象中给出 ...../index

需要:

我需要将编译后的.js 文件放入baseapplication/movies_list/static/movies_listbaseapplication/series_list/static/series_list 中。所以我需要在entry 中找到每个条目并获取abs 路径并为将来的应用程序动态构建我的output 路径。这将帮助我的python manage.py collectstatic 从每个目录中获取静态文件。

如何配置output 使其动态化?

module.exports = {

  //The base directory (absolute path) for resolving the entry option
    context: __dirname,

entry: {
  movies:  '../movies_list/interfaces/index',  
  series:  '../series_list/interfaces/index',
 },

output: {      
 // I need help here.
  path: path.join('<', "static"),
  //path: path.resolve('../[entry]/static/react_bundles/'), 
  filename: "[name].js",
},

}

https://github.com/webpack/docs/wiki/configuration

【问题讨论】:

    标签: python django node.js reactjs webpack


    【解决方案1】:

    您可以将入口点设置为生成文件的完整路径。这样的事情应该可以工作:

    module.exports = {
    
      context: __dirname,
    
      entry: {
        'baseapplication/movies_list/static/movies_list/index':  '../movies_list/interfaces/index',
        'baseapplication/series_list/static/series_list/index':  '../series_list/interfaces/index',
       },
    
      output: {
        path: './',
        filename: "[name].js",
      },
    
    }
    

    【讨论】:

    • 感谢@lukasz 的回答。但问题是我的 web-pack 配置位于名为 baseapplication/react_support/web-pack.config.js 的目录中。因此,使用./ 作为路径将完整路径设置为入口点实际上是在创建baseapplication/react_support/baseapplication/movies_list/static/movies_list/index.js。相反,我想要的是baseapplication/movies_list/static/movies_list/index.js,我想要它是动态的。所以output 中的path 应该以某种方式使用条目值。
    • 好的,我想我明白了。谢谢:)
    猜你喜欢
    • 2018-11-21
    • 1970-01-01
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多