2015-08-10 4 views
1

Я хочу, чтобы перейти от requirejs к WebPack и в requirejs конфигурации у меня есть:WebPack модули зависимостей как в requirejs

paths: { 
    'jquery.ui.core': 'lib/jquery.ui/jquery.ui.core-1.11.4', 
    'jquery.ui.draggable': 'lib/jquery.ui/jquery.ui.draggable-1.11.4', 
    'jquery.ui.mouse': 'lib/jquery.ui/jquery.ui.mouse-1.11.4', 
    'jquery.ui.widget': 'lib/jquery.ui/jquery.ui.widget-1.11.4', 
... 
shim: { 
    'jquery.ui.mouse': ['jquery.ui.core', 'jquery.ui.widget'], 
.... 

jquery.ui.core и jquery.ui.widget являются зависимостями jquery.ui.mouse. Как заставить webpack загружать эти модули в зависимости от jquery.ui.mouse?

Какая альтернатива зависимостей webpack от shim свойства конфигурации?

ответ

1

нужно использовать "импорт-погрузчик" для shim: https://github.com/webpack/imports-loader

loaders: [..., { 
    // if use npm module 'jquery-ui' instead of 'lib/...' directory in question 
    include: require.resolve('jquery-ui/ui/mouse'), 
    loader: "imports-loader?dep1=jquery.ui.core&dep2=jquery.ui.widget" 
}, ...] 

И path следует использовать resolve.alias

resolve: { 
    ... 
    alias: { 
    'jquery.ui.core': 'jquery-ui/ui/core', 
    'jquery.ui.draggable': 'jquery-ui/ui/draggable', 
    'jquery.ui.droppable': 'jquery-ui/ui/droppable', 
    'jquery.ui.mouse': 'jquery-ui/ui/mouse', 
    'jquery.ui.sortable': 'jquery-ui/ui/sortable', 
    'jquery.ui.widget': 'jquery-ui/ui/widget', 
    ... 
    } 
... 
} 
Смежные вопросы