I am going to implement code splitting with server side rendering. For that i am using react-loadable.
But, i am getting following error while using import.
I show other posts but, nothing work for me.
You may need an appropriate loader to handle this file type. | var Content = (0, _reactLoadable.default)({ | loader: function loader() { return import('./components/Content'); | },
My code looks like:
import Loadable from 'react-loadable';
const Content = Loadable({
loader: () => import('./components/Content'),
loading: Loading
});
package.json
"dependencies": {
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"acorn-dynamic-import": "^4.0.0",
"express": "^4.16.4",
"isomorphic-fetch": "^2.2.1",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-loadable": "^5.5.0",
"react-redux": "^5.1.1",
"react-router": "^4.3.1",
"react-router-config": "^1.0.0-beta.4",
"react-router-dom": "^4.3.1",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/node": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.3.1",
"@babel/preset-react": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.0.0",
"babel-loader": "^7.1.5",
"css-loader": "^1.0.1",
"cypress": "^3.1.3",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
"enzyme-to-json": "^3.3.5",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"fetch-mock": "^7.2.5",
"jest": "^24.0.0",
"jest-fetch-mock": "^2.0.1",
"json-loader": "^0.5.7",
"nodemon": "^1.18.9",
"npm-run-all": "^4.1.5",
"open": "0.0.5",
"redux-devtools": "^3.4.2",
"redux-mock-store": "^1.5.3",
"style-loader": "^0.23.1",
"uglifyjs-webpack-plugin": "^2.0.1",
"webpack": "^4.26.1",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.14",
"webpack-node-externals": "^1.7.2"
},
"babel": {
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-class-properties",
"react-loadable/babel",
"@babel/plugin-syntax-dynamic-import"
]
}
webpack.config.js
return {
context: path.join(__dirname, "src"),
entry: './index.js',
mode: isProduction ? "production" : "development",
devtool: isProduction ? "none" : "source-map",
resolve: {
extensions: [".js", ".jsx"]
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: "babel-loader",
exclude: /node_modules/,
options: {
presets: ['@babel/preset-env', '@babel/preset-react']
}
},
{
test: /\.(ttf|eot|svg|woff|png|jpg)$/,
loader: "file-loader",
options: {
name: "[path][name].[ext]?[hash]"
}
},
{
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
}
]
},
optimization: isProduction ? {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true
}),
new OptimizeCSSAssetsPlugin({})
]
} : {},
devServer: {
contentBase: path.resolve(__dirname, "dist"),
historyApiFallback: true,
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, "dist"),
publicPath: "/",
}
};