首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何禁用AMD上的4个文件和加载顺序与webpack

如何禁用AMD上的4个文件和加载顺序与webpack
EN

Stack Overflow用户
提问于 2017-01-05 23:03:42
回答 1查看 1.1K关注 0票数 0

我需要禁用AMD的4个文件和加载video.js首先加载其他3个文件,因为他们依赖它。当我尝试在webpack.config.js中这样做时:

代码语言:javascript
复制
const path = require('path')
const webpack = require('webpack')

module.exports = {
  entry: './src/main.js',
  output: {
    path: __dirname + '/public',
    filename: 'bundle.js'
  },
  devServer: {
    inline: true,
    contentBase: './src',
    port: 3333
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
        'NODE_ENV': JSON.stringify('production')
      }
    })
  ],
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules|lib/,
        loader: 'babel',
        query: {
          presets: ['es2015', 'react', 'stage-2'],
          plugins: ['transform-class-properties']
        }
      },
      {
        test: /\.json$/,
        loader: 'json-loader'
      },
      {
        test: /[\/\\]lib[\/\\](video|playlist|vpaid|overlay)\.js$/,
        exclude: /node_modules|src/
        loader: 'imports?define=>false'
      }
    ]
  }
}

这并不是真正的工作,因为它只是加载video.js (禁用了AMD),并完全忽略其他3个文件。

我的文件夹结构是这样的:

代码语言:javascript
复制
▾ lib/
    overlay.js
    playlist.js
    video.js
    vpaid.js
▸ node_modules/
▾ public/
    200.html
    bundle.js
▾ src/
    App.js
    index.html
    main.js
  LICENSE
  package.json
  README.md
  webpack.config.js

现在,我发现了一些让我后退一步的东西,因为现在甚至连video.js都不能加载:

代码语言:javascript
复制
require('imports?define=>false!../lib/video.js')
require('imports?define=>false!../lib/playlist.js')
require('imports?define=>false!../lib/vpaid.js')
require('imports?define=>false!../lib/overlay.js')

而只是抛出这些类型的警告:

代码语言:javascript
复制
WARNING in ./~/imports-loader?define=>false!./lib/video.js
Critical dependencies:
15:415-422 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./~/imports-loader?define=>false!./lib/video.js 15:415-422

WARNING in ./~/imports-loader?define=>false!./lib/playlist.js
Critical dependencies:
10:417-424 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./~/imports-loader?define=>false!./lib/playlist.js 10:417-424

WARNING in ./~/imports-loader?define=>false!./lib/vpaid.js
Critical dependencies:
4:113-120 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./~/imports-loader?define=>false!./lib/vpaid.js 4:113-120

WARNING in ./~/imports-loader?define=>false!./lib/overlay.js
Critical dependencies:
10:416-423 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ./~/imports-loader?define=>false!./lib/overlay.js 10:416-423

所以,我的问题是,我如何在webpack.config.js中实现这一点,这样我就不会收到这些警告?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-06 01:24:23

我已经解决了这个问题!要使其正常工作,您需要以下内容:

代码语言:javascript
复制
 {
    test: /[\/\\]lib[\/\\](video|playlist|vpaid|overlay)\.js$/,
    exclude: /node_modules|src/
    loader: 'imports?define=>false'
  }

还有这个

代码语言:javascript
复制
require('script-loader!../lib/video.js')
require('script-loader!../lib/playlist.js')
require('script-loader!../lib/vpaid.js')
require('script-loader!../lib/overlay.js')

一起来!

现在,如果你使用这个(而不是脚本加载器):

代码语言:javascript
复制
require('imports?define=>false!../lib/video.js')
require('imports?define=>false!../lib/playlist.js')
require('imports?define=>false!../lib/vpaid.js')
require('imports?define=>false!../lib/overlay.js')

这行不通的!(您需要同时使用导入加载器和脚本加载器。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41488225

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档