Bootstrap с Webpack Encore работает с внутренним веб-сервером Symfony 4, но не с LAMP - PullRequest
0 голосов
/ 06 октября 2019

Я использую Webpack Encore с проектом Symfony 4. Bootstrap работает, если я запускаю php bin / console server: запускаю и я захожу на http://127.0.0.1:8000

Но, когда я запускаю Apache, чтобы использовать ссылку http://localhost/show-my-pictures/public/index.php Bootstrapперестать функционировать. И разработчик консоли дает мне:

The script from “http://localhost/build/runtime.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.

Я не понимаю, что происходит. Можете ли вы помочь мне, пожалуйста?

Webpack.config.js

var Encore = require('@symfony/webpack-encore');
var CopyWebpackPlugin = require('copy-webpack-plugin'); // this line tell to webpack to use the plugin

Encore
    // directory where compiled assets will be stored
    .setOutputPath('public/build/')
    // public path used by the web server to access the output path
    .setPublicPath('/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', './assets/js/app.js')

    /*
     * FEATURE CONFIG
     *
     * Enable & configure other features below. For a full
     * list of features, see:
     * https://symfony.com/doc/current/frontend.html#adding-more-features
     */
    .cleanupOutputBeforeBuild()
    .enableBuildNotifications()
    .enableSourceMaps(!Encore.isProduction())

    .enableSingleRuntimeChunk()

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

    // enables Sass/SCSS support
    .enableSassLoader()

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

    .addPlugin(new CopyWebpackPlugin([
        { from: './assets/images', to: 'images' }
    ]))
;

module.exports = Encore.getWebpackConfig();

1 Ответ

0 голосов
/ 06 октября 2019

Ваш публичный путь неверен при запуске приложения в Apache, что приводит к неправильной загрузке ресурсов.

Поскольку в этом случае у вас есть подкаталог (show-my-pictures), его следует использоватьпри звонках Encore.setPublicPath():

Encore.setPublicPath('/show-my-pictures/build')

См .: https://symfony.com/doc/current/frontend/encore/faq.html#my-app-lives-under-a-subdirectory

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...