[英]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?就像使用ProvidePlugin预加载jQuery一样,有没有办法预加载第三方的css和js文件,而不是在入口js文件中使用import?
Why I would like to preload these files is that I am getting an error when importing jQuery-ui in the entry js file.我之所以要预加载这些文件,是因为在入口js文件中导入jQuery-ui时出现错误。 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. ./assets/js/jquery-ui.min.js 关键依赖项:719:76-84 这似乎是一个预先构建的 javascript 文件。 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
@ ./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.您应该在 webpack 配置的
entry
导入第三方 css 文件。 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" }
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.