Can I use webpack to generate CSS and JS separately?

后端 未结 7 2007
长情又很酷
长情又很酷 2020-12-02 07:37

I have:

  1. JS files that I want to bundle.
  2. LESS files that I want to compile down to CSS (resolving @imports into a single bundle).

I was

7条回答
  •  时光取名叫无心
    2020-12-02 08:23

    You can also put your Less require statements in your entry JS file also:

    in body.js

    // CSS
    require('css/_variable.scss')
    require('css/_npm.scss')
    require('css/_library.scss')
    require('css/_lib.scss')
    

    Then in webpack

      entry: {
        body: [
          Path.join(__dirname, '/source/assets/javascripts/_body.js')
        ]
      },
    
    const extractSass = new ExtractTextPlugin({
      filename: 'assets/stylesheets/all.bundle.css',
      disable: process.env.NODE_ENV === 'development',
      allChunks: true
    })
    

提交回复
热议问题