无法修复Modernizr:无法解决Webpacker Rails中的“生成”错误?

时间:2018-10-15 11:02:53

标签: ruby-on-rails webpacker

首先,yarn add modernizr modernizr-loader json-loader

然后,用

创建config/webpack/loaders/modernizr-config.json
{

  "minify": true,
  "options": [
    "setClasses"
  ],
  "feature-detects": []
}

然后,用创建config/webpack/loaders/modernizr.js

const path = require('path');

module.exports = {
  module: {
    rules: [
      {
        test: /modernizr-config\.json$/,
        use: [
          {
            loader: 'modernizr-loader',
            options: require('./modernizr-config.json'),
          },
          'json-loader'
        ]
      },
    ]
  },
  resolve: {
    extensions: [ '.js', '.json' ],
    modules: [
      'node_modules'
    ],
    alias: {
      modernizr$: path.resolve(__dirname, '/modernizr-config.json')
    }
  }
}

最后,将上述文件导入到config/webpack/environment.js

const modernizr = require('./loaders/modernizr')

environment.config.merge(modernizr)

从node_modules导入modernizr之后,

import * as Modernizr from '../../../../../node_modules/modernizr';

并运行./bin/webpack时,出现以下错误:

ERROR in ./node_modules/modernizr/lib/build.js
Module not found: Error: Can't resolve 'generate' in '/private/var/www/project/node_modules/modernizr/lib'
 @ ./node_modules/modernizr/lib/build.js 151:2-72
 @ ./node_modules/modernizr/lib/cli.js
 @ ./app/assets/javascripts/packs/application.ts

ERROR in ./node_modules/modernizr/lib/build.js
Module not found: Error: Can't resolve 'lib/generate-banner' in '/private/var/www/project/node_modules/modernizr/lib'
 @ ./node_modules/modernizr/lib/build.js 151:2-72
 @ ./node_modules/modernizr/lib/cli.js
 @ ./app/assets/javascripts/packs/application.ts

ERROR in ./node_modules/modernizr/lib/build.js
Module not found: Error: Can't resolve 'package' in '/private/var/www/project/node_modules/modernizr/lib'
 @ ./node_modules/modernizr/lib/build.js 151:2-72
 @ ./node_modules/modernizr/lib/cli.js
 @ ./app/assets/javascripts/packs/application.ts

ERROR in ./node_modules/requirejs/bin/r.js
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
| #!/usr/bin/env node
| /**
|  * @license r.js 2.1.22 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved.
 @ ./node_modules/modernizr/lib/build.js 133:18-38
 @ ./node_modules/modernizr/lib/cli.js
 @ ./app/assets/javascripts/packs/application.ts

0 个答案:

没有答案