简体   繁体   中英

How to preload third-party's css and js files using webpack in ReactJS project?

Like using ProvidePlugin to preload jQuery, is there a way to preload a third-party's css and js files instead of using import in the entry js file?

Why I would like to preload these files is that I am getting an error when importing jQuery-ui in the entry js file. Also, I think it is good to preload the libraries.

./assets/js/jquery-ui.min.js Critical dependencies: 719:76-84 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results. @ ./assets/js/jquery-ui.min.js 719:76-84

Thank you in advanced!

You should import third party css files at entry on webpack config. like example below:

module.exports = {
  entry: {
    'main': [
      'bootstrap-sass!./src/theme/bootstrap.config.js',
      './src/client.js',
      './src/someCSSFILE.js'
    ]
  },
  output: {
    path: assetsPath,
    filename: 'bundle.js',
    publicPath: 'http://' + host + ':' + port + '/dist/',
  },
  module: {
    loaders: [
      { test: /\.jsx?$/, exclude: /node_modules/, loaders: ['babel?' + JSON.stringify(babelLoaderQuery), 'eslint-loader']},
      { test: /\.json$/, loader: 'json-loader' },
      { test: /\.less$/, loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!less?outputStyle=expanded&sourceMap' },
      { test: /\.scss$/, loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap' },
      { test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" }
 ]

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM