Less-Loader: Import URLs are treated as relative URLs, without passing the -relative-url option

I am trying to use less-loader to load a smaller file with url import at the top. This url import is for a file that is located elsewhere (on cdn).

app.less

@import url("http://cdn-name/mixins.less");

When I try to download this file with a smaller bootloader, I get the following error:

ERROR in ./~/css-loader!./~/less-loader!./static-content/less/app.less
Module build failed: Cannot resolve 'file' or 'directory' ./http://cdn-name/mixins.less 

It appears that the smaller bootloader treats my url import as a relative path, rather than actually discovering that it is its own url that contains the resource to be extracted.

The configuration of my webpack is as follows:

module.exports = {
  entry: {
    bundle: ['./static-content/js/index.js'],
    vendor: ['react', 'react-dom']
  },
  output: {
    path: jsGeneratedPath,
    filename: 'bundle.min.js',
    publicPath: 'http://localhost:8444/assets/',
    hotUpdateChunkFilename: 'hot/js-update.js',
    hotUpdateMainFilename: 'hot/json-update.json',
    recordsPath: path.resolve(__dirname, '/assets/hot/')
  },
  stats: {
    colors: true,
    reasons: true
  },
  module: {
    preLoaders: [
      {
        test: /\.jsx?$/,
        loader: 'eslint-loader',
        exclude: /node_modules/
      }
    ],
    loaders: [
      {
        test: /.js?$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        progress: true
      },
      {
        test: /.less$/,
        loader: 'style!css!less',
        exclude: /node_modules/,
        progress: true
      }
    ]
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      names: ['vendor'],
      minChunks: Infinity,
      filename: '[name].min.js'
    })
  ]
}

, ? , - , ( ), , css ( CD- Google ), .

URL.

webpack v 1.13.1 webpack-dev-server v 1.14.1 v 2.2.3

+4
1

. .

 {
      loader: require.resolve('less-loader'),
      options: {
          importLoaders: 1,
          paths: [path.resolve(__dirname, "node_modules")],

      },
  }
0

Source: https://habr.com/ru/post/1657538/


All Articles