Webpack bundle all css and load first

﹥>﹥吖頭↗ 提交于 2020-01-04 05:28:36

问题


How to bundle all the css file together and load on the top of the head before the document loads using webpack ?


回答1:


From my understanding, using a dummy .js file in order just to build a global/shared css bundle which imports needed css files may be a solution. I don't know if this is a best practice but works for me. An alternative approach may bu using Webpack together with Gulp, but it means an extra step will be required in every build.

So in webpack.config.js I have an entry such as:

        entry: {
          'product-detail': './Assets/js/pages/product-detail.js',
          'product-list': './Assets/js/pages/product-list.js',
          'global-css-generator': './Assets/js/global-css-generator.js'
          'common-bundle': ['jquery']
        },

In global-css-generator.js file, I just import the needed less files:

        import './../../less/bootstrap.less';
        import './../../less/global.less';
        .
        .


来源:https://stackoverflow.com/questions/39698124/webpack-bundle-all-css-and-load-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!