Вставьте модули RequireJS AMD с помощью Webpack Encore - PullRequest
0 голосов
/ 11 декабря 2018

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

Похоже, что кому-то здесь удалось, но я не уверен, что этовозможно с Webpack Encore: Webpack с 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?

1 Ответ

0 голосов
/ 12 декабря 2018

У меня нет опыта работы с 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;

Удачи!

...