vue中全局引入cornerstone.js
cornerstone.js解析Dicom图像并显示第一步: 配置 build/webpack.base.conf.js'use strict'const path = require('path')const utils = require('./utils')const config = require('../config')const vueLoaderConfig = ...
·
第一步: 配置 build/webpack.base.conf.js
'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
const webpack = require("webpack")
function resolve(dir) {
return path.join(__dirname, '..', dir)
}
module.exports = {
context: path.resolve(__dirname, '../'),
entry: {
app: './src/main.js'
},
output: {
path: config.build.assetsRoot,
filename: '[name].js',
publicPath: process.env.NODE_ENV === 'production' ?
config.build.assetsPublicPath : config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json'],
modules: [
resolve('src'),
resolve('node_modules')
],
// 下面 引入
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
'assets': resolve('src/assets'),
'components': resolve('src/components'),
'cornerstone': 'cornerstone-core',
'dicomParser': 'dicom-parser',
'cornerstoneWADOImageLoader': resolve("static/dist/cornerstoneWADOImageLoader.js")
}
},
plugins: [
// 使用 cornerstone-core & dicom-parser & cornerstoneWADOLoader
new webpack.ProvidePlugin({
cornerstone: "cornerstone-core",
"window.cornerstone": "cornerstone-core",
dicomParser: 'dicom-parser',
"window.dicomParser": "dicom-parser",
cornerstoneWADOImageLoader: "cornerstoneWADOImageLoader",
"window.cornerstoneWADOImageLoader": "cornerstoneWADOImageLoader"
})
],
module: {
rules: [{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
},
node: {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
}
}
第二步: src/main.js
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
//引入 cornerstone,dicomParser,cornerstoneWADOImageLoader
import * as cornerstone from "cornerstone-core";
import * as dicomParser from "dicom-parser";
// 不建议 npm 安装 cornerstoneWADOImageLoader 如果你做了 会很头疼
import * as cornerstoneWADOImageLoader from "../static/dist/cornerstoneWADOImageLoader.js";
Vue.use(ElementUI, {
size: 'small',
zIndex: 3000
});
Vue.use(cornerstone);
Vue.use(dicomParser);
Vue.use(cornerstoneWADOImageLoader);
//指定要注册加载程序的基石实例
cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
/*
*配置 webWorker (必须配置)
*
*注意这里的路径问题 如果路径不对 cornerstoneWADOImageLoaderWebWorker 会报错:
* "index.html Uncaught SyntaxError: Unexpected token <"
*
*/
var config = {
webWorkerPath: "/static/dist/cornerstoneWADOImageLoaderWebWorker.js",
taskConfiguration: {
decodeTask: {
codecsPath: "/static/dist/cornerstoneWADOImageLoaderCodecs.js"
}
}
};
cornerstoneWADOImageLoader.webWorkerManager.initialize(config);
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: {
App
},
template: '<App/>'
})
其他的 引入使用此方法即可
引入成功后 需 重启项目
更多推荐
已为社区贡献4条内容
所有评论(0)