Last active
February 13, 2021 20:28
-
-
Save mxstbr/7723a02e1156d35f04802870a5355694 to your computer and use it in GitHub Desktop.
How to use webpack to compile node modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-var */ | |
var path = require('path'); | |
var autoprefixer = require('autoprefixer'); | |
const MATCH_ALL_NON_RELATIVE_IMPORTS = /^\w.*$/i; | |
module.exports = [{ | |
output: { | |
filename: '[name].js', | |
library: 'atrium-react-plugin-beta', | |
libraryTarget: 'commonjs2', | |
path: path.join(__dirname, 'dist'), // where to place webpack files | |
}, | |
entry: { | |
plugin: './plugin.js', | |
'server/run': './server/run.js', | |
}, | |
module: { | |
loaders: [{ | |
test: /\.js$/, | |
loader: 'babel', | |
}], | |
}, | |
externals: [MATCH_ALL_NON_RELATIVE_IMPORTS, { | |
'./frontend/index.js': 'commonjs ./frontend/index.js', | |
}], | |
target: 'node', | |
node: { | |
__dirname: false, | |
__filename: false, | |
} | |
}, { | |
output: { | |
filename: '[name].js', | |
library: 'atrium-react-plugin-beta', | |
libraryTarget: 'commonjs2', | |
path: path.join(__dirname, 'dist'), // where to place webpack files | |
}, | |
entry: { | |
'frontend/index': './frontend/index.js', | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.js$/, | |
loader: 'babel', | |
}, | |
{ | |
test: /\.css$/, | |
// eslint-disable-next-line max-len | |
loader: 'style-loader!css-loader?modules&importLoaders=1&localIdentName=atriumReactPlugin__[local]__[hash:base64:5]!postcss-loader', | |
}, | |
], | |
}, | |
externals: [MATCH_ALL_NON_RELATIVE_IMPORTS], | |
target: 'web', | |
postcss: [autoprefixer({ browsers: ['> 1%'] })], | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment