-->

How do we extract CSS chunks file in Laravel with

2019-08-29 00:46发布

问题:

I am working in Laravel with Vue.js and in my webpack.config.js file I am extracting the js chunks file like this:

mix.webpackConfig({
    resolve: {
        alias: {...
            'Helpers': path.resolve(__dirname, 'resources/js/helpers/'),
            'Themes': path.resolve(__dirname, 'resources/js/themes/')
        ...}
    },
    output: {
        chunkFilename: 'js/chunks/[name].js',
    },
});

This extract the js chunks file like 0.js , 1.js ,2.js etc. I want to extract the CSS chunks in same way.

回答1:

I was having the same problem with vuely xd. For now what I have done this:

mix.autoload({
    'jquery': ['$', 'window.jQuery', 'jQuery'],
})

mix.webpackConfig({
    resolve: {
        alias: {
            'Api': path.resolve(__dirname, 'resources/js/api/'),
            'Components': path.resolve(__dirname, 'resources/js/components/'),
            'Constants': path.resolve(__dirname, 'resources/js/constants/'),
            'Container': path.resolve(__dirname, 'resources/js/container/'),
            'Views': path.resolve(__dirname, 'resources/js/views/'),
            'Helpers': path.resolve(__dirname, 'resources/js/helpers/'),
            'Themes': path.resolve(__dirname, 'resources/js/themes/')
        }
    },
    output: {
        chunkFilename: mix.inProduction() ? "js/chunks/[name].[chunkhash].js" : "js/chunks/[name].js",
    }
});


mix.options({
    extractVueStyles: true
});

mix.js('resources/js/main.js', 'public/js');
mix.sass('resources/js/assets/scss/_style.scss', 'public/css/style.css');