相对路径在webpack

时间:2017-04-03 07:36:48

标签: webpack webpack-2 webpack-style-loader

使用nw.js运行时,Webpack为CSS文件提供了错误的URL。

  

file:/// C://Application/dirA/dirB/dirC/dirA/dirB/dirC/node_modules/style-small/style-small.min.css无法加载资源:net :: ERR_FILE_NOT_FOUND

相对路径 dirA / dirB / dirC 将被添加两次

请参阅以下目录结构和webpack-config.js

C:\<path>\Application
               |- nw.exe
               |- webpack.config.js
               |- dirA
                    |- dirB
                         |- dirC
                              |- node_modules
                              |- index.html
                              |- bundle.js  
                              |- entry.js

的WebPack-config.js

var path = require("path");
module.exports = {

  entry: './dirA/dirB/dirC/entry.js',
  output: {
    path: __dirname + '/dirA/dirB/dirC',
    filename: 'index.js',
    libraryTarget: 'umd',
  },

  module: {
    rules: [
      { test: /node_modules/, loader: "imports-loader?define=>undefined" },
    ],
  },
  resolve: {
    extensions: ['.js', '.css'],
    modules: [
      path.resolve(__dirname, "./dirA/dirB/dirC/node_modules"),
    ],

  },
  devtool: 'source-map',
  target: 'node-webkit',

  externals: {
    'slack-node' : 'Slack-node',
  },

  node: {
   __dirname: true
  },
};

entry.js

.......
require('style-small'); // CSS file from node_modules
require('style-extra-small'); // CSS file from node_modules

window.onload = function() {
..................
}

0 个答案:

没有答案