script-loader

安装

  1. npm install --save-dev script-loader

用法

在全局上下文(global context)执行一次 JS 脚本。

:警告: 在 node.js 中不会运行

#

  1. import exec from 'script.exec.js';

webpack.config.js

  1. module.exports = {
  2. module: {
  3. rules: [
  4. {
  5. test: /\.exec\.js$/,
  6. use: [ 'script-loader' ]
  7. }
  8. ]
  9. }
  10. }

内联

  1. import exec from 'script-loader!./script.js';

Options

Name

Type

Default

Description

Name

sourceMap

Type

{Boolean}

Default

false

Description

Enable/Disable Sourcemaps

sourceMap

Type: Boolean Default: false

To include source maps set the sourceMap option.

webpack.config.js

  1. module.exports = {
  2. module: {
  3. rules: [
  4. {
  5. test: /\.script\.js$/,
  6. use: [
  7. {
  8. loader: 'script-loader',
  9. options: {
  10. sourceMap: true,
  11. },
  12. },
  13. ]
  14. }
  15. ]
  16. }
  17. }

维护人员

script-loader - 图1


Juho Vepsäläinen

script-loader - 图2


Joshua Wiens

script-loader - 图3


Kees Kluskens

script-loader - 图4


Sean Larkin