无法使用Webpack解决@模块

时间:2018-12-03 16:06:46

标签: javascript webpack

我想问一下如何解决以@开头的模块,因为不是以@开头的所有模块都可以正常工作。

我的webpack.config.js

const path = require('path');
const glob = require('glob');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = (env, options) => ({
  optimization: {
    minimizer: [
      new UglifyJsPlugin({ cache: true, parallel: true, sourceMap: false }),
      new OptimizeCSSAssetsPlugin({})
    ]
  },

  entry: {
    './js/app.js': ['./js/app.js'].concat(glob.sync('./vendor/**/*.js'))
  },
  output: {
    filename: 'app.js',
    path: path.resolve(__dirname, '../priv/static/js')
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader'
        }
      },
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader']
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({ filename: '../css/app.css' }),
    new CopyWebpackPlugin([{ from: 'static/', to: '../' }])
  ]
});

我的入口点js文件:

import css from '../css/app.css';
import 'phoenix_html';
import 'spectre.css';
import '@yaireo/tagify';

错误消息:

Module not found: Error: Can't resolve '@yaireo/tagify' in '/home/hei/Desktop/elixir/pluma/assets/js'
 @ ./js/app.js 13:0-24
 @ multi ./js/app.js

1 个答案:

答案 0 :(得分:0)

直接从软件包内的 src 文件夹中导入。

import Tagify from "@yaireo/tagify/src/tagify";

工作sandbox