Answer the question
In order to leave comments, you need to log in
How to setup babel plugin root import package?
Link to package .
webpack:
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const autoprefixer = require('autoprefixer');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const eslintFormatter = require('react-dev-utils/eslintFormatter');
const htmlWebpackPluginConfig = new HtmlWebpackPlugin({
template: './src/index.html',
filename: './index.html',
});
const miniCssExtractConfig = new MiniCssExtractPlugin({
filename: '[name].[hash].css',
chunkFilename: '[id].[hash].css',
});
const copyWebpackPlugin = new CopyWebpackPlugin([
{
context: './server/images',
from: '**/*',
to: './images'
}
]);
// настройки babel plugin root import
const babelPluginRootImport = [
"babel-plugin-root-import",
{
"rootPathPrefix": "#",
"rootPathSuffix": "./src",
}
];
module.exports = {
entry: './src/index.js',
output: {
path: `${__dirname}/dist`,
publicPath: '/',
filename: 'main.js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
{
options: {
formatter: eslintFormatter,
eslintPath: require.resolve('eslint'),
},
loader: require.resolve('eslint-loader'),
},
],
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: [
autoprefixer({
browsers: ['> 0%'],
}),
],
sourceMap: true,
},
},
],
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[local]__[hash:base64:5]',
},
},
{
loader: 'postcss-loader',
options: {
plugins: [
autoprefixer({
browsers: ['> 0%'],
}),
],
},
},
'less-loader',
],
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.css', '.less'],
},
plugins: [
htmlWebpackPluginConfig,
copyWebpackPlugin,
miniCssExtractConfig,
autoprefixer,
babelPluginRootImport,
],
devServer: {
contentBase: './dist',
open: 'chrome',
},
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question