Disable Strict Mode in None Module Library

Viewed 221

I want to bundle a JavaScript project by WebPack but there is more problems in none-module libraries because imported them by 'import' capability,ECMAScript 6 module loader run strict mode by default and it tack more errors.

Question :

How can I import none module libraries without strict mode to bundle them by WebPack?

index.js
import '../examples/js/libs/draco/draco_encoder.js';
import './js/libs/codemirror/codemirror.js';
import './js/libs/codemirror/mode/javascript.js';
import './js/libs/codemirror/mode/glsl.js';
...
webpack.config.js
const path = require('path');
const webpack = require('webpack');

// webpack.config.js
module.exports = {
    entry: {
        polyfills: './editor/polyfills',
        index: './lib/index.js',
    },
    mode: 'development',
    output: {
        path: __dirname,
        publicPath: '/',
        filename: './editor/[name].bundle.js',
        path: path.resolve(__dirname, 'dist'),
    },
    devServer: {
        watchContentBase: true,
        publicPath: "/",
        contentBase: "./",
        hot: true,
        port: 8080,
    },
    module: {
        rules: [
            {
                test: /\.m?js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: ['@babel/preset-env']
                    }
                }
            }
        ]
    }
};
babel.config.json
{
    "presets": [
        "@babel/preset-env"
    ]
}

I tryed :

  1. babel
  2. esmify
  3. browserify
  4. Shimming in WebPack
  5. ... Thanks for your attention.
1 Answers

Webpack enables use of loaders to preprocess files. This allows you to bundle any static resource way beyond JavaScript. About loaders: Loaders. You can easily write your own loaders using Node.js : Writing Loader. For execute JS script once in global context that can solved my problem : Script Loader

Related