Подключайте модули RequireJS AMD с помощью Webpack Encore

У меня есть куча модулей RequireJS AMD, которые мне нужно включить в мой проект и подключить с помощью Webpack.

Похоже, что кому-то удалось сделать это здесь, однако я не уверен, что это возможно с Webpack encore: Веб-пакет с requirejs/AMD

Это мой webpack.config.js:

var Encore = require('@symfony/webpack-encore');

Encore
    // directory where compiled assets will be stored
    .setOutputPath('web/build/')

    // public path used by the web server to access the output path
    .setPublicPath('/app/build')

    // only needed for CDN's or sub-directory deploy
    .setManifestKeyPrefix('build/')

    /*
     * ENTRY CONFIG
     *
     * Add 1 entry for each "page" of your app
     * (including one that's included on every page - e.g. "app")
     *
     * Each entry will result in one JavaScript file (e.g. app.js)
     * and one CSS file (e.g. app.css) if you JavaScript imports CSS.
     */
    .addEntry('app', './web/assets/js/app.js')

    // will require an extra script tag for runtime.js
    // but, you probably want this, unless you're building a single-page app
    .enableSingleRuntimeChunk()

    .cleanupOutputBeforeBuild()

    .enableSourceMaps(!Encore.isProduction())

    // enables hashed filenames (e.g. app.abc123.css)
    .enableVersioning(Encore.isProduction())

    // uncomment if you use Sass/SCSS files
    .enableSassLoader()

    // uncomment if you're having problems with a jQuery plugin
    .autoProvidejQuery()
;

module.exports = Encore.getWebpackConfig();

Как я могу получить свои модули RequireJS?


person crmpicco    schedule 11.12.2018    source источник


Ответы (1)


У меня вообще нет опыта работы с requirejs/AMD в Webpack. Однако в нижней части файла webpack.config.js вы можете изменить конфигурацию Webpack по своему усмотрению. Например:

const config = Encore.getWebpackConfig();

// make changes
// I don't know if these are correct - just referencing the
// other SO you linked to
config.output.library = '[name]';
config.output.libraryTarget = 'amd';
config.output.umdNamedDefine = true;


module.exports = config;

Удачи!

person weaverryan    schedule 12.12.2018