auto-inject-loader
v1.0.7
Published
Auto import the source what we need
Downloads
6
Readme
用法
在webpack配置里面加
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
include: [resolve('src')],
use: ['thread-loader', 'cache-loader', {
loader: 'babel-loader',
}, {
loader: 'auto-inject-loader',
options: {
autoImport: [
{
name: 'localSocket',
paths: 'src/lib/core/index.js'
}
]
}
}]
}
]
}
}
auto-inject-loader
Options
autoImport
Type: Array
name: 当前在页面使用的变量
paths: 变量定义所在哪个文件路径下
eg:
会在js部分生成如下
import localSocket from 'src/lib/core/index.js'
注意事项:
- 如果项目使用了eslint校验,需要在eslintrc.js 添加
globals: {
localSocket: true // 此处localSocket即是在options里面定义的name
}