Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] support {String|Function} input for hot reloading (options.modifyVars) #229

Closed
stackjie opened this issue Nov 14, 2017 · 12 comments

Comments

@stackjie
Copy link

stackjie commented Nov 14, 2017

webpack config

{
  test: /\.less$/,
  loader: 'less-loader',
  options: {
     modifyVars: theme
   }
}

theme.js

module.exports = {
  '@primary-color ': '#4578c8',
  '@info-color': '#049df8',
  '@success-color': '#6ccb24',
  '@warning-color': '#ffb619',
  '@error-color': '#f30416',
  '@input-bg': '#fbfdfc',
  '@table-thead-bg': '@input-bg'
}

every change in theme.js I have to restart the server npm run😆,how to hot reload?
thanks

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Nov 14, 2017

You can try for watch mode at least

webpack.config.js

{
   test: /\.less$/,
   use: [
      {
         loader: 'less-loader', 
         options: (loader) => {
             loader.addDependency('path/to/theme')

             return {
                modifyVars: theme
             }
         }
      }
   ]
}

But I'm not 💯, if it works with less-loader, this may require a PR to accept a {Function} for modifyVars

webpack.config.js

{
   test: /\.less$/,
   use: [
      {
         loader: 'less-loader', 
         options: {
           ident: 'less',
           modifyVars: (loader) => {
             loader.addDependency('path/to/theme')
            
             return require('path/to/theme')
           }
        }
      }
   ]
}

@stackjie
Copy link
Author

stackjie commented Nov 15, 2017

@michael-ciniawsky Seems to not accept the Function for options?

error info

    throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
                ^

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module.rules[8].use should be one of these:
   non-empty string | function | object { loader?, options?, query? } | function | [non-empty string | function | object { loader?, options?, query? }]

my configuration by vue-cli webpack template
vuejs-templates/webpack

  // generate loader string to be used with extract text plugin
  function generateLoaders (loader, loaderOptions) {
    var loaders = [cssLoader]
    if (loader) {
      loaders.push({
        loader: loader + '-loader',
        options: (loader) => {
          loader.addDependency('../src/styles/theme/esf')
          return Object.assign({}, loaderOptions, {
            sourceMap: options.sourceMap,
            modifyVars: theme
          })
        }
        // options: Object.assign({}, loaderOptions, {
        //   sourceMap: options.sourceMap,
        //   modifyVars: theme
        // })
      })
    }

    // Extract CSS when that option is specified
    // (which is the case during production build)
    if (options.extract) {
      return ExtractTextPlugin.extract({
        use: loaders,
        fallback: 'vue-style-loader'
      })
    } else {
      return ['vue-style-loader'].concat(loaders)
    }
  }

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Nov 15, 2017

Yeah, that's what I meant with 'maybe' 😞, we need to accept a {Function} for modifyVars and handle it inside the loader. If you want to go for it feel free to open a PR and I will help if needed, otherwise I will tackle it when time

@stackjie
Copy link
Author

stackjie commented Nov 15, 2017

@michael-ciniawsky ok,thanks😁

@michael-ciniawsky michael-ciniawsky changed the title How to changed modifyVars after hot reload. [Feature] support {String|Function} input for hot reloading (options.modifyVars) Nov 16, 2017
@tim-soft
Copy link

tim-soft commented Dec 2, 2017

Anything I can do to help make this a reality?
Designing themes via less loader's modifyVars is pretty painful without HMR support

@ghost
Copy link

ghost commented Jan 31, 2019

Any news on this PR please ?

@Aka4Code
Copy link

Aka4Code commented Aug 6, 2019

@michael-ciniawsky Do you plan to add hot reloading here?

@alexander-akait
Copy link
Member

PR welcome

@alexander-akait
Copy link
Member

We implement prependData in next major release, it is same as modifyVars and it is support Function

@ButuzGOL
Copy link

ButuzGOL commented Nov 2, 2020

Is there any information how can it be achieved ?
Currently to see my changes i need to restart server which takes time

@alexander-akait
Copy link
Member

@ButuzGOL
Copy link

ButuzGOL commented Nov 3, 2020

This helped me
#303 (comment)
but anyway not so fast as with less variant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants