3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

React:Importの相対パスから絶対パスの切替

Posted at
相対パス:import FuncGroup from '../../components/english/FuncGroup';
絶対パス:import FuncGroup from 'root/components/english/FuncGroup';

絶対パスを有効するには、webpack.config.jsの設定が必要です。

webpack.config.js
module.exports = {
  devtool: "source-map",
  context: __dirname + "/src",
  entry: './index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'build')
  },
  devServer: {
    contentBase: 'build',
    port: 3000
  },
★★★★★★★★★★★★
  resolve: {
    alias: {
      root: path.resolve(__dirname, 'src/'),
      styles: path.resolve(__dirname, 'styles/'),
    }
  },
★★★★★★★★★★★★
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loaders: ["babel-loader"],
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loaders: ["eslint-loader"],
      },
      {
        test: /\.html$/,
        loader: "file?name=[name].[ext]",
      },
      {
        test: /\.css$/,
        loaders: ['style-loader', 'css-loader?modules'],
      }
    ],
  },
}
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?