这是indexloc提供的服务,不要输入任何密码
Skip to content

solution for Next Js in IE11 after add Polyfills #7993

@anwer-kalghoum

Description

@anwer-kalghoum

Question about Next.js in IE11

I added Polyfills in my project nextjs, but all the scripts js are not functional in IE11 (internet explorer):
https://github.com/zeit/next.js/tree/canary/examples/with-polyfills

// polyfills.js
/* eslint no-extend-native: 0 */
// core-js comes with Next.js. So, you can import it like below
import includes from 'core-js/es/string/virtual/includes';
import repeat from 'core-js/es/string/virtual/repeat';
import assign from 'core-js/es/object/assign';
// add your polyfills
// This files runs at the very beginning (even before React and Next.js core)
console.log('Load your polyfills');
String.prototype.includes = includes;
String.prototype.repeat = repeat;
Object.assign = assign;


// next.confg.js
`require('dotenv').config();
const path = require('path');
const Dotenv = require('dotenv-webpack');
const withCSS = require('@zeit/next-css');
console.log(__dirname);
module.exports = withCSS({
cssLoaderOptions: {
url: false,
},
distDir: '../build',
pageExtensions: ['jsx', 'js'],
webpack: config => {
const originalEntry = config.entry;
config.entry = async () => {
const entries = await originalEntry();

  if (entries['main.js'] && !entries['main.js'].includes('./client/polyfills.js')) {
    entries['main.js'].unshift('./client/polyfills.js');
  }

  return entries;
};

config.module.rules.push({
  test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
  use: {
    loader: 'url-loader',
    options: {
      limit: 100000,
    },
  },
});
config.plugins = config.plugins || [];
config.plugins = [
  ...config.plugins,

  // Read the .env file
  new Dotenv({
    path: path.join(__dirname, '.env'),
    systemvars: true,
  }),
];

return config;

},
});
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions