Webpack Config忽略在其他地方定义和编译的导入

时间:2019-06-15 19:20:12

标签: javascript webpack babeljs

我在一个单独的项目中定义了一组React组件。将它们编译并捆绑到JavaScript文件中没问题。

我现在想在我当前的项目中使用它们,我想对其进行编译,并可以根据服务器端逻辑通过script标签将其包含在我的站点中。

我试图避免为这些组件创建npm软件包,而是尝试通过webpack config或其他方式“包含”它们。

例如:

import Foo from 'ComponentOutsideThisProject'

class CustomComponent extends React.Component {    
    render() {
        return (<Foo bar={123} />);
    }
}

相关的Webpack配置:

  resolve: {
    modules: [
      'node_modules',
      path.resolve(__dirname, '../other-app/dist')
    ],
    extensions: ['.js', '.jsx']
  }

编译后,无法检测到ComponentOutsideThisProject

如果将modules的点ComponentOutsideThisProject指向CustomComponent的未编译版本,则由于缺少预设,它无法编译。即使这些预设已添加到我当前的项目中,它们也不会应用到此文件(我想是的,当然如此)。

我如何编译script并将其作为JavaScript文件分发,然后通过ComponentOutsideThisProject标签CustomComponent的捆绑JavaScript包含在内?

我还研究了代码拆分/分块,但这似乎要求我使用动态导入,而动态导入需要重写Application.ScreenUpdating = False Application.Calculation = xlCalculationAutomatic Application.DisplayStatusBar = False Application.EnableEvents = False Set wb = ThisWorkbook Set ws = wb.Worksheets("WHITE") n = 0 ' Outer loop 'goes' through your original table and for each cell in ' column D checks how many instances there are. For i = 2 To 523 instancesInRow = ws.Cells(i, 4).Value level1 = ws.Cells(i, 5).Value level2 = ws.Cells(i, 6).Value level3 = ws.Cells(i, 7).Value level4 = ws.Cells(i, 8).Value level5 = ws.Cells(i, 9).Value ' Inner loop 'knows' how many times it needs to loop-copy the same ' row into the new table/worksheet. For a = 1 To level1 n = n + 1 ws.Range("J" & n & ":M" & n).Value = ws.Range("A" & i & ":I" & i).Value ws.Range("N" & n).Value = 1 ws.Range("O" & n).Value = 0 ws.Range("P" & n).Value = 0 ws.Range("Q" & n).Value = 0 ws.Range("R" & n).Value = 0 Next a For b = 1 To level2 n = n + 1 ws.Range("J" & n & ":M" & n).Value = ws.Range("A" & i & ":I" & i).Value ws.Range("N" & n).Value = 0 ws.Range("O" & n).Value = 1 ws.Range("P" & n).Value = 0 ws.Range("Q" & n).Value = 0 ws.Range("R" & n).Value = 0 Next b For c = 1 To level3 n = n + 1 ws.Range("J" & n & ":M" & n).Value = ws.Range("A" & i & ":I" & i).Value ws.Range("N" & n).Value = 0 ws.Range("O" & n).Value = 0 ws.Range("P" & n).Value = 1 ws.Range("Q" & n).Value = 0 ws.Range("R" & n).Value = 0 Next c For d = 1 To level4 n = n + 1 ws.Range("J" & n & ":M" & n).Value = ws.Range("A" & i & ":I" & i).Value ws.Range("N" & n).Value = 0 ws.Range("O" & n).Value = 0 ws.Range("P" & n).Value = 0 ws.Range("Q" & n).Value = 1 ws.Range("R" & n).Value = 0 Next d For e = 1 To level5 n = n + 1 ws.Range("J" & n & ":M" & n).Value = ws.Range("A" & i & ":I" & i).Value ws.Range("N" & n).Value = 0 ws.Range("O" & n).Value = 0 ws.Range("P" & n).Value = 0 ws.Range("Q" & n).Value = 0 ws.Range("R" & n).Value = 1 Next e ' Counter n counts how many rows you have copied so far, 'in order to know in which row to copy to the new range Next i Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic Application.DisplayStatusBar = True Application.EnableEvents = True End Sub

帮助!

0 个答案:

没有答案